K
K
krock000002016-02-09 23:50:13
Delphi
krock00000, 2016-02-09 23:50:13

How can one read a command from a txt file and execute it on the command line using delphi?

There will be an interesting file. When launched from the site, a txt file with commands is downloaded, and you need to execute them on the command line. I decided to try to do this, but so far it does not work out very well. Can anyone help? Or give advice?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Fedoryan, 2016-02-10
@AnnTHony

To read a file so
With command line to work so
What is impossible?

O
ORTOL, 2016-02-11
@ORTOL

Hello.
Firstly, everything can be done much easier without Delphi, namely with the help of a BAT file.
Secondly, if you need to do just that, then here is the code ...

procedure TForm1.Button1Click(Sender: TObject);
var txt:TStringList;
begin
 If FileExists('command.txt') Then Begin
 txt := TStringList.Create;
 txt.LoadFromFile('command.txt');
 WinExec(PAnsiChar('cmd /c '+txt.Strings[0]), SW_HIDE);
 txt.Free;
 // txt.Strings[0] это означает что из тхт файла будет прочтена первая строка
 // если нужна вторая то 0 меняешь на 1 и так далее ...
 end else ShowMessage('Командный файл "'+'command.txt'+'" отсутствует');
end;

An example of the contents of the command.txt file
This line contains two commands, they are separated by "&".
The first command is to delete the file "DEL | ERASE C:\file.txt".
Then comes the separator "&".
Second command "md c:\folder" Create folder folder in C drive.
That's it. At startup, the file file.txt is deleted from drive C and the folder folder is created there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question