Question

I'm having issues with stdout ordering. I'm spawning an Altera QuartusII process which executes a tcl script using its built in Tcl interpreter and then quits.

When I run the process from command prompt on Windows and/or a bash shell on Linux, the stdout order looks like this:

Synthesizing
... lots of quartus_map and quartus_cdb messages ...
Fitting 
... lots of quartus_fit messages ...

However, when I spawn the process using Qt's QProcess and read the full stdout buffer when the process finished, the order looks like this:

... lots of quartus_map and quartus_cdb messages ...
... lots of quartus_fit messages ...
Synthesizing
Fitting 

The tcl script I run looks something like this:

puts stdout "Synthesizing"
flush stdout
if { [ catch {qexec "quartus_map $proj -c $rev" } ] } {
     post_message -type error "Error: quartus_map failed: ${::errorInfo}"
     exit
}
if { [ catch {qexec "quartus_cdb $proj -c $rev --merge" } ] } {
     post_message -type error "Error: quartus_cdb failed: ${::errorInfo}"
     exit
}

puts stdout "Fitting"
flush stdout
if { [ catch {qexec "quartus_fit $proj -c $rev" } ] } {
   post_message -type error "Error: quartus_fit failed: ${::errorInfo}"
   exit
}

I have no idea why the order is different. Any help or ideas on how to get the correct ordering using QIODevice would be much appreciated. All messages are available on stdout, there is nothing on stderr as expected.

EDIT: It can be reproduced by this simple piece of code:

QProcess* process = new QProcess;
QStringList args;
args << "-t";
args << "test.tcl";
process->setWorkingDirectory("D:/work/fpga_designs/my_design");
process->start("C:/tools/Altera/Quartus/13.0/quartus/bin/quartus_sh", args, QProcess::ReadWrite);
if (!process->waitForStarted(30000)) {
    process->waitForFinished();
    return 1;
}
while (process->state() == QProcess::Running || process->state() == QProcess::Starting) {
    QCoreApplication::processEvents();
}
process->setReadChannelMode(QProcess::MergedChannels);
QByteArray ba_stdout = process->readAllStandardOutput();
qDebug() << ba_stdout;
Was it helpful?

Solution

Fixed it thanks to @Harald.

It was indeed due to the merged channel mode I used and the way Quartus puts all its messages on STDERR by default. STDOUT appears after STDERR in the buffer due to the way Qt does the merging.

The fix is to either not use merged channels, or to post messages on stderr:

puts stderr "Synthesizing"
flush stderr
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top