View Full Version : QProcess finishes imediately (it shouldn't)

10th September 2012, 16:52
I'm running Windows XP and I'm using Qt Creator, and here is the code I use to create the process and to log what is happening:

QProcess process;
cout << "Starting process..." << endl;
process.start("ping -n 1 -w 3000 > nul");
cout << "Process started" << endl;
cout << "Process finished" << endl;

The command line "ping -n 1 -w 3000 > nul" is supposed to make the program halt for 3 seconds (3000 milliseconds) between two pings before it times out, but the text "Process finished" is written to cout almost simultaneously as the other two lines of text, sometimes seemingly at the same time. If the command line is entered directly into the terminal (MS Command Prompt) instead, the command runs for three seconds before the terminal takes in keyboard input again, so it is not the command line that is wrong. So why isn't this working in Qt?

11th September 2012, 01:22
QProcess is not running a shell thus things like ">" will not work. It doesn't make sense to use it here anyway since QProcess is capturing all the output of the slave process.

11th September 2012, 10:13
Okay, that seems reasonable. I started another program instead which also waits for a centain amount of time, and that worked fine. Thanks!