I need to send commands to the STDIN of an already running process (specifically, a cmd instance) using C++ and the Windows API. However, I don’t want to launch the process myself — I only want to reference the process by its process ID (PID) in my program and interact with its STDIN. I do not need the output to be visible, only for the commands to run. How can I achieve this?
3
You can’t write to the STDIN of another process that you did not start yourself. When you start a new process using CreateProcess()
, you have the option to redirect the new process’ STDIN to read from a pipe that you control and can write to. But without that, the best you can do is just post simulated keystrokes using SendInput()
and hope they reach the cmd
window if it is in focus.
1