Search code examples
delphidelphi-10.2-tokyo

How to run a command-line program and send keys while running in Delphi?


I can open a command-line program by using:

ShellExecute(Handle, 'open', 'example.exe', nil, nil, SW_SHOWNORMAL) ;

The program waits user input (for example the key "q"). How can i send keys to the program while it is running?


Solution

  • As advised by Uwe Raabe,

      DosCommand1.CommandLine:='example.exe';
      DosCommand1.Execute;
      ...
      DosCommand1.SendLine('q',True);