PDA

View Full Version : QProcess Standard Output



Decessus
14th August 2012, 20:31
Hello, I am writing a utility in Qt 4.8 that basically automates several tasks for my area of software development. Some of the tools I am looking to automate require the usage of WINE. Everything is running as expected except when a tool requiring WINE encounters a logical error, it seems that I only receive errors from WINE itself and not the error information from the application running within WINE.

Example:
bash output:

fixme:heap:HeapSetInformation (nil) 1 (nil) 0
fixme:process:SetProcessDEPPolicy (1): stub
fixme:heap:HeapSetInformation (nil) 1 (nil) 0
fixme:heap:HeapSetInformation (nil) 1 (nil) 0
fixme:module:GetModuleHandleExW should pin refcount for 0x79000000
MMP: error MMP0000: Cannot locate file for assembly 'xxxx'
MMP: error MMP0000: CLR_E_ENTRY_NOT_FOUND


QProcess output:

fixme:heap:HeapSetInformation (nil) 1 (nil) 0
fixme:process:SetProcessDEPPolicy (1): stub
fixme:heap:HeapSetInformation (nil) 1 (nil) 0
fixme:heap:HeapSetInformation (nil) 1 (nil) 0
fixme:module:GetModuleHandleExW should pin refcount for 0x79000000


Now, in both cases I used the exact same command. My usage of QProcess is as follows:

MainProcess = new QProcess(this);
MainProcess->setProcessChannelMode(QProcess::MergedChannels);
MainProcess->start(command,QIODevice::ReadWrite);
if(!MainProcess->waitForFinished())
{
//handle errors
}
ui->textEdit->append(MainProcess->readAllStandardOutput());


readAllErrorOutput() returns nothing (as expected) and readAll() returns the exact same output as readAllStandardOutput().

What am I doing wrong here? Any help would be greatly appreciated, thank you.

Ginsengelf
15th August 2012, 07:12
Hi, this looks like the WINE output is written to stdout, but the program's error is written to stderr.
Have you tried QProcess::readAllStandardError() to read stderr?
Maybe you can also try to write the messages to a file (QProcess::setStandardErrorFile() and QProcess::setStandardOutputFile()) and then read those files.

Ginsengelf

edit: it seems you already tried readAllStandardError()...

edit2: are you sure your application does start and not only WINE? Did you separate the command (wine) and the arguments? I often got weird effects when I tried to pass the arguments together with the command in one QString. Use the overloaded start() method and pass the arguments as a QStringList, maybe this helps.

ChrisW67
15th August 2012, 09:03
It is possible the the "wine" program is spawning a child process with independent stdout/stderr streams.

Decessus
15th August 2012, 14:33
It is possible the the "wine" program is spawning a child process with independent stdout/stderr streams.

If this is the case (as it seems the most logical) is there anyway for me grab or inherit the streams from the child process? I know that this is possible on Windows, but I am unsure about on Linux.


Hi, this looks like the WINE output is written to stdout, but the program's error is written to stderr.
Have you tried QProcess::readAllStandardError() to read stderr?
Maybe you can also try to write the messages to a file (QProcess::setStandardErrorFile() and QProcess::setStandardOutputFile()) and then read those files.

Ginsengelf

edit: it seems you already tried readAllStandardError()...

edit2: are you sure your application does start and not only WINE? Did you separate the command (wine) and the arguments? I often got weird effects when I tried to pass the arguments together with the command in one QString. Use the overloaded start() method and pass the arguments as a QStringList, maybe this helps.

Yes, the "fixme" errors show that there is a stream of communication between wine and the application.

Decessus
15th August 2012, 17:10
I have come up with a temporary solution to my problem, however, this created another problem. I decided to try and echo the output to a file, and then parse that file during clean up. However, I can not issue an echo command that works for either echoing to a file or simply echoing to stdout. Upon googling this new issue, I found the same question was asked on another site, however the only answer given was "You should instead use QFile so you can tell if you have written any data or not.". While his point is valid, I obviously can not write nothing to a file through QFile. Is there special modes/enviroments I must set up to get echo to work properly?