0

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?

Xel Naga
  • 826
  • 11
  • 28
  • 1
    Not using `ShellExecute`! Use `CreateProcess` and attach the stdin of the new process to the read end of a pipe that you create. Feed the input into the other end, the write end, of that pipe. This is not for the faint of heart. If you aren't already skilled with win32, then you may be best looking for a library. – David Heffernan Jan 05 '18 at 12:33
  • 2
    The GetIt Package Manger in 10.2 Tokyo offers a library named DosCommand which provides such functionality. – Uwe Raabe Jan 05 '18 at 12:35
  • See [Creating a Child Process with Redirected Input and Output](https://msdn.microsoft.com/en-us/library/windows/desktop/ms682499.aspx) on MSDN. – Remy Lebeau Jan 05 '18 at 17:09

1 Answers1

0

As advised by Uwe Raabe,

  DosCommand1.CommandLine:='example.exe';
  DosCommand1.Execute;
  ...
  DosCommand1.SendLine('q',True);
Xel Naga
  • 826
  • 11
  • 28