I am working on an application (developed in Qt 5.11, toolchain MSVS2017 64bit) which will, at some point, have to execute a .bat script. This .bat script will call certain program with appropriate cmd line arguments. Script and program will reside in same directory. This program may or may not require user to press Enter at the end. If program requires user to press Enter, program would never finish unless new line character is written in stdin.
I want to check if program is waiting for user input before trying to write to its stdin, if possible using only Qt library.
The .bat script would simply call program:
Program arg1 arg2 arg3...
From application, script would execute using QProcess:
Added spleep after start of process
QProcess process;
process.setWorkingDirectory("C:/path/to/script");
process.start("cmd /C C:/path/to/script/script.bat");
QThread::sleep(someTimeout); // give enough time for process to finish
if (/*somehow*/ process.isWaitingForInput())
proces.write("\n");
process.waitForFinished();
process.readAllStandardOutput();
process.readAllStandardInput();
proces.exitCode();
I have found similar question with answer pointing to MSDN WaitForInputIdle.
In future port to Linux or Mac is possible and if it is possible I would like to avoid
#if defined(WIN32)
WaitForInputIdle(...)
#else
PosixAlternative(...)
#endif
Also, maybe of topic, but I am curious, is it possible to to execute .bat script from QProcess in a way that cmd/terminal window is shown along with std output?