PDA

View Full Version : QProcess and console programs



bond_e
3rd July 2007, 16:51
Hello )
When start console program using QProcess's start() function, this program is invisible (no window). Is it possible to start it in window but have control on it by means of QProcess (start/stop, view status etc)?

wysota
4th July 2007, 17:48
You'd have to open a terminal program (like xterm) from QProcess and ask it to run the application you wish to control. But it might be easier if you dedicate a text edit widget where you will just display the output of the application.

bond_e
6th July 2007, 17:01
Unfortunatelly its not always possible to catch console program output - it is often buffered and not available.
xterm works, and hope on all *nix platforms, including Mac?
But do you know similar workaround in windows ?

wysota
9th July 2007, 16:30
What do you mean by buffered? If it's buffered, you won't see it in the terminal as well... So using xterm (or not) wouldn't change a thing.

bond_e
10th July 2007, 09:11
What do you mean by buffered? If it's buffered, you won't see it in the terminal as well... So using xterm (or not) wouldn't change a thing.
for example, such code:
puts("Some strings..");
gets(s);
puts(s);
...
will not output anything to QProcess until console program end
But if you add
setvbuf(stdout,NULL,0,_IOFBF); before these strings, it will work.

wysota
10th July 2007, 10:07
Have you heard about a function called fflush()?

bond_e
11th July 2007, 09:28
Have you heard about a function called fflush()?
where can i use this function? console programs i told about aren't my and i can't do anything with its code.
as i understand, QProcess is implemented so that it never show console program window - and i wonder why it isn't an option.. so i need to invent various workarounds. very strange imho.

evgenM
11th July 2007, 18:51
it's your?
http://prog.org.ru/forum/topic_5677_17e042b9bbb04459f33b312ed38e6971.html
;)

i have try


fflush(stdout);

after puts(s); -- and all work right;
so problem to call flush in your class -- maybe start timer after myProc.write() with little delay

evgenM
12th July 2007, 08:29
check this


QProcess::closeWriteChannel ()

bond_e
12th July 2007, 16:11
Well, it seems i need to specify some details:
Suppose i have console program (worked in text mode), without any source - only executable (so i cant change anything in this program, like put fflush() somewhere in it), which periodically outputs some info to the screen (for example, gets it from network), and allows me to input some "commands" which it then "process" and shows me result. To stop this program i need to enter "quit" command.
I want to start several such programs from one Qt application and have ability to check running status and stop/restart them if necessay. And also it would be very desirable to get access to program console.
But if i do that with QProcess start() method, i cant get program window, cant view program output and cant input anything (well, may be can - but dont see it).
If i use startDetached() - i get program window, but lose control at it from my Qt application.
Any ideas?

evgenM: closeWriteChannel() works in my simple example (just stop it), but doesnt work in other cases

evgenM
13th July 2007, 09:39
i realy not understand the problem - u do right all u must do - problem only in this bugged console app (no flush) - i am not sure u can fix it in YOUR app. So u have one way - ask author to correct.