Cannot get stdout from QProcess
I am having trouble to retrieve the console output from an external program. Below, I modified the program so that it is similar to what I have in my program - but with the external program changed to "dir /w".
Code:
Parameters<<"/w";
System_Call.start("dir",Parameters);
System_Call.waitForStarted();
X = System_Call.readAll();
System_Call.waitForFinished();
Parameters.clear();
I cannot seem to retrieve the output from this program... what am I doing wrong?:confused:
Re: Cannot get stdout from QProcess
What about readAllStandardOutput() ?
Re: Cannot get stdout from QProcess
I think you should read after the process has finished.
Re: Cannot get stdout from QProcess
Quote:
Originally Posted by wysota
I think you should read after the process has finished.
but if app using flush(stdout) first method can be possible?
Re: Cannot get stdout from QProcess
Quote:
Originally Posted by zlatko
but if app using flush(stdout) first method can be possible?
No, because you still might try to read the data before the process has written it.
Re: Cannot get stdout from QProcess
Hmm.. this works fine on Linux (Ubuntu, Qt 4.1.1, gcc 4.0.2) but not in Windows (XP+SP2, Qt4.1.1, VS2003).
Code:
proc.waitForFinished(-1);
qDebug() << proc.readAll();
Edit: means that it outputs correct info in linux, and nothing in windows..
Re: Cannot get stdout from QProcess
Quote:
Originally Posted by jpn
Hmm.. this works fine on Linux (Ubuntu, Qt 4.1.1, gcc 4.0.2) but not in Windows (XP+SP2, Qt4.1.1, VS2003).
Code:
proc.waitForFinished(-1);
qDebug() << proc.readAll();
Edit: means that it outputs correct info in linux, and nothing in windows..
Is the Qt application built as console, or are you checking the dDebug output with the debugger? Otherwise you wont see any qDebug output on windows.
Re: Cannot get stdout from QProcess
Quote:
Originally Posted by seneca
Is the Qt application built as console, or are you checking the dDebug output with the debugger? Otherwise you wont see any qDebug output on windows.
With a debugger... I can see qDebug() outputs fine, that is not the problem.
Re: Cannot get stdout from QProcess
Reading all output at once, even after the application is finished is not a very good idea. For short outputs it is fine, but if you expect a large amount of data to come through that pipe, you should use a signal/slot mechanism to read the data as it comes in. Why? Because it may happen that you fill the pipe buffer between those two processes and the child process will never finish, because it'll be waiting until some of the buffer is read so that it can write all the remaining data. So you should use readyReadStdout() and family.
Re: Cannot get stdout from QProcess
My point is, that I never get any output on windows with the above code.
Even when I set the working dir so that the output is expected to be extremely short.
Re: Cannot get stdout from QProcess
Quote:
Originally Posted by jpn
My point is, that I never get any output on windows with the above code.
Even when I set the working dir so that the output is expected to be extremely short.
Because there is no "dir" executable on Windows. "dir" is a command.com (or cmd.exe) command, so you have to run it from the shell. There are threads on this forum that cover the topic, maybe you should take a look at them.
Re: Cannot get stdout from QProcess
Quote:
Originally Posted by wysota
Because there is no "dir" executable on Windows. "dir" is a command.com (or cmd.exe) command, so you have to run it from the shell. There are threads on this forum that cover the topic, maybe you should take a look at them.
Ahh, now I get the point..