简体   繁体   English

QProcess不会在Windows 7下启动Java应用程序

[英]QProcess doesn't start java app under windows 7

I'm writing a windows application using Qt (4.6.1) that uses QProcess class to execute a java application. 我正在使用Qt(4.6.1)编写一个使用QProcess类来执行java应用程序的Windows应用程序。

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. 这就是我启动java应用程序的方式,它工作正常但是我只在我的Windows XP机器上测试过。 When I tested this on another computer with Windows 7, it failed. 当我在另一台装有Windows 7的计算机上测试时,它失败了。

In Windows 7, the QProcess signal error(QProcess::ProcessError) is emitted after process->start(...) giving me the error QProcess::FailedToStart 在Windows 7中,在process-> start(...)之后发出QProcess信号错误(QProcess :: ProcessError ),给出错误QProcess :: FailedToStart

Also I tested this: QStringList arguments; 我也测试了这个:QStringList参数; arguments << "/c"; 参数<<“/ c”; arguments << "java"; arguments <<“java”; arguments << "-jar"; arguments <<“ - jar”; arguments << "absolute_path\\app.jar"; arguments <<“absolute_path \\ app.jar”; //the java app that I want to execute arguments << "-blah-blah"; //我想执行参数的java应用程序<<“ - blah-blah”; //some java app's arguments process->start( "cmd.exe", arguments ); //一些java app的参数process-> start(“cmd.exe”,arguments); But then cmd.exe complains not finding java... 但是后来cmd.exe抱怨找不到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). 很明显,java安装在Windows 7机器上(从cmd.exe手动调用它)。

You might want to check the QProcess environment as mentioned in the docs. 您可能需要检查文档中提到的QProcess环境。 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. 我见过应用程序/ QProcess的环境与登录用户环境有很大不同的情况,因此当从代码执行某些操作时它不起作用,但是当执行与系统用户完全相同的命令时,它可以工作。

Try dumping to what QProcess thinks it's environment looks like and see what is there: 尝试转储到QProcess认为它的环境看起来像什么,看看有什么:

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

Hope that will help you get it working. 希望能帮助你实现目标。

I know it's been a long time, but I just experienced the same problem. 我知道这已经很久了,但我刚遇到同样的问题。 I was running a bash script that contained a java execution in a QProcess, and everything except the java output was captured by the readyRead.. signals and mapped functions. 我正在运行一个包含QProcess中的java执行的bash脚本,除了java输出之外的所有内容都由readyRead ..信号和映射函数捕获。

The solution for me was to add the bash redirect 2>&1 to the jave line: 我的解决方案是将bash重定向2>&1到jave行:

java -cp %(cpPath)s org.opensha.step.calc.STEP_main 2>&1

That worked for me. 这对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM