Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QProcess doesn't start java app under windows 7

Tags:

c++

qt4

I'm writing a windows application using Qt (4.6.1) that uses QProcess class to execute a java application.

Here's basically the code:

process = new QProcess(this);
connect( process, SIGNAL( started() ),                  this, SLOT( onProcessStarts() ) );
connect( process, SIGNAL( finished(int) ),              this, SLOT( onProcessEnds(int) ) );
connect( process, SIGNAL( readyReadStandardOutput() ),  this, SLOT( onProcessOutputs() ) );
connect( process, SIGNAL( error(QProcess::ProcessError)), this, SLOT(onProcessError(QProcess::ProcessError)));

QStringList arguments;
arguments << "-jar";
arguments << "absolute_path\app.jar";   //the java app that I want to execute
arguments << "-blah-blah";              //some java app's arguments
process->start( "java", arguments );

This is how I start the java application, and it works ok BUT, as far as I tested only in my Windows XP machine. When I tested this on another computer with Windows 7, it failed.

In Windows 7, the QProcess signal error(QProcess::ProcessError) is emitted after process->start(...) giving me the error QProcess::FailedToStart

Also I tested this: QStringList arguments; arguments << "/c"; arguments << "java"; arguments << "-jar"; arguments << "absolute_path\app.jar"; //the java app that I want to execute arguments << "-blah-blah"; //some java app's arguments process->start( "cmd.exe", arguments ); But then cmd.exe complains not finding java...

I suspect there's some permission issue involved; I set my executable to be run as administrator, but no luck, so I have run out of ideas...

Obivously, java is installed in Windows 7 machine (calling it manually from cmd.exe works).

like image 511
Pherrymason Avatar asked May 19 '26 08:05

Pherrymason


1 Answers

You might want to check the QProcess environment as mentioned in the docs. I have seen cases where the applications / QProcess's environment differs quite a bit from the logged in users environment, so when executing something from code it does not work but when executing the exact same command as a system user it works.

Try dumping to what QProcess thinks it's environment looks like and see what is there:

qDebug() << QProcess::environment();

Hope that will help you get it working.

like image 183
Christopher Avatar answered May 21 '26 22:05

Christopher