PDA

View Full Version : How to run a console program "silently"?



fullmetalcoder
16th July 2006, 20:06
When running a console program through QProcess in a GUI app, you normally expect that nothing pops up and that all output can be smoothly parsed by your app for the confort of the user. unfortunately this is only partly working... When running a console app under windows (9x/ME series at least, I didn't tested under XP) an ugly console windows appears, even if all output is redirected by QProcess. Having used a bunch of apps running console process without seing this console windows appearing I know that what I'm trying to achieve is possible but I don't know how... Source code of other apps, such as Code::Blocks or Dev-Cpp doesn't help much( C::B is written with wxWindows and Dev-Cpp is written in Delphi)...

Any hints ?

jacek
16th July 2006, 20:42
How do you start that external application? Maybe you start it through cmd.exe?

fullmetalcoder
18th July 2006, 09:19
Nop!

I start them through a QProcess object, and not QProcess::startDetached(), itself owned by a running non-GUI QThread.

jacek
19th July 2006, 19:44
I've created a small test:
#include <QApplication>
#include <QProcess>
#include <QMessageBox>
#include <QString>

int main( int argc, char **argv )
{
QApplication app( argc, argv );

QProcess proc;
proc.start("g++ --version");
proc.waitForFinished();

QString output( proc.readAllStandardOutput() );

QMessageBox::information( 0, "test", output );

return 0;
}and it doesn't open console window. Maybe this is because you start QProcess in another thread?

fullmetalcoder
21st July 2006, 15:04
This does not work...

Mmmh, yes it does work but the console windows still appears... It must be specific to Win 9x/ME ...

jacek
21st July 2006, 15:50
It must be specific to Win 9x/ME ...
It could be, I've tested above program on windows XP.

lewis
21st July 2006, 20:59
win9x/ME ??? I thought they died quite a while ago....

fullmetalcoder
22nd July 2006, 11:28
do you? You were wrong then... There at least on winME still running on that good old Earth! :)

But is that the point anyway?

jpn
22nd July 2006, 18:25
"Good old earth"? Isn't WinME famous of it's memory leaks and stuff. I thought it's maybe the worst Windows ever.. :p

fullmetalcoder
23rd July 2006, 10:03
It certainly is a great piece of Window$-coding with all the bugs and leaks it implies... AFAI Used it it crashes 1 time over 3 at run-time!!! Impressive, huh?:D Tha's why I'm using Fedora most of the time, but as it is the only Window$ I've got I use it to test my code so...