How do you read that output? Maybe it stops becuse of full buffers?
How do you read that output? Maybe it stops becuse of full buffers?
I read it by doing!Originally Posted by jacek
ui.textBrowser->append(nh3d.readAllStandardOutput());
and the program do not stop! It never ends
Each time the readyReadStandard...() signal is emitted?Originally Posted by antonio.r.tome
Yes, you're reading all the standard output, but only one time. You need to connect the signal readyReadStandardOutput to a slot for using readAllStandardOutput.
Say the process you are running sends
"Blah blah blah blah blah
Blah blah blah blah blah
Blah blah blah blah blah
Blah blah blah blah blah
Blah blah blah blah blah"
to stdout. Your call to nh3d.readAllStandardOutput() picks it up, which is fine. But now say the process wants to say
"Blah blah blah blah blah" again and you are not checking to see if anything is there.
If you don't want to do signals and slots, and you don't need interactive use of the program until the other process finishes, you can use a blocking wait:
Just make sure the while loop does not run foreverQt Code:
if (nh3d.state() ==0 ) nh3d.start("c:\\winnt\\system32\\mem"); { if (nh3d.waitForReadyRead(MAXIMUM TIME IN MILLISECONDS YOU ARE WILLING TO WAIT FOR THE PROCESS TO SEND SOMETHING TO THE STREAM) == TRUE) dosomethingwiththedata; else decidewhattodoiftheprocessisn'tsendingyouanythingafteralongtime,likekillingitandexiting; }To copy to clipboard, switch view to plain text mode. In this pseudocode, it probably would unless the program normally exits on its own.
My philosophy is: If you can use a free, open-source alternative: do it. And if you can't, pretend it's free and open-source and hope you don't get caught.
[QUOTE=michel]Yes, you're reading all the standard output, but only one time. You need to connect the signal readyReadStandardOutput to a slot for using readAllStandardOutput.
I'm sorry I didn't sent you all the code!
I'm already reading the standard Output in a slot of a function connected to readyReadStandardOutput signal!
and as I said it works great in Linux.
I have the follwoing code aditional code.
.....
QObject::connect(&nh3d, SIGNAL(readyReadStandardOutput ()), &readwrite, SLOT(owrite()));
QObject::connect(&nh3d, SIGNAL(readyReadStandardError ()), &readwrite, SLOT(ewrite()));
readwrite is a class with the slots owrite e ewrite
.............................
void Readoutput:write()
{
ui.textBrowser->append(nh3d.readAllStandardOutput());
/
}
void Readoutput::ewrite()
{
ui.textBrowser_2->append(nh3d.readAllStandardError());
......................
Because this weird problem today I'm going to Update my windiows 2000 to XP to see if the problem solves by itself.
Best regards,
Hm. Weird. Maybe processes in Windows just don't behave correctly (that would sure be a surprise).
My philosophy is: If you can use a free, open-source alternative: do it. And if you can't, pretend it's free and open-source and hope you don't get caught.
Do those slots get called at all?
YesOriginally Posted by wysota
if i put a command with large output. (I use nh3d an executable program of my one, where the standards erro and output are flushed every time they are used) I obtain the full output in stderr and the output of stdout behaves great but for the last two or three lines. It happens as the external processed freezed just before finished.
The example I put were I call mem was only to see if with a native windows application I got some output, but the behavior is the same.
I've just update for XP but the results are the same.
António Tomé
I've solved de problem:
In my example
QProcess nh3d
is definided as a global variable (C++ books are always alerting to avoid them ...)
Kwow I've defined
QProcess nh3d as a plublic variable of the class which contais the slot that starts the Qprocess and everthing works fine in linux and windows.
The remaining, and maybe unuseful, question is to know what are the right question:
Why it didn't work as was in windows? Or
why it work as it was in linux?
my best Regards and many thanks to everyone o tried to help
António Tomé
One possible explanation is that it was instantiated before QCoreApplication, which performes some platform-dependent initialization.Originally Posted by antonio.r.tome
Bookmarks