Answer the question
In order to leave comments, you need to log in
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
To read a file so
With command line to work so
What is impossible?
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;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question