I've written a program that starts another process and redirects its standard I/O to pipes using the windows API (CreateProcess, CreatePipe, etc.)
The program should start multiple different console programs and communicate with them using stdio.
This was all working well (I could write to the stdin of the process and read from the process using the pipes) until I tried to start and communicate with a program that was using kbhit.
To simplify it what that program I'd like to start does with the standard input:
while(1)
{
if(kbhit())
{
fgets(line, sizeof(line), stdin);
//do something with line
}
Sleep(100);
}
The result is that fgets gets never called because kbhit doesn't return true even though I've written to the pipe that I've redirected stdin to. I know that because I've debugged into the other program. I've tried to remove the call of kbhit and then it does work but I can't change that code.
Is there a way to send something to the process so that that kbhit in the child process returns true?
kbhit
reads the keyboard directly instead of reading via stdin. Why do you needkbhit
here? Is this an XY Problem? – Jabberwockykbhit()
is not a standard function in C++. You'll need to read the documentation for the compiler/library used to build the "other program" in order to know how to interact with it - assuming that is even possible. – Peter_kbhit
read from console (CONIN$
device). it ignore stdin. what you write to stdin will be ignored – RbMm