我正在寫一個Windows應用程序使用Qt(4.6.1),它使用QProcess類來執行Java應用程序。QProcess不啓動Windows應用程序下的Java應用程序
這裏的基本代碼:
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);
我這是怎麼開始的Java應用程序,並且正如我在我的Windows XP機器只測試了它的工作原理確定,但據。當我在另一臺裝有Windows 7的電腦上測試它時,它失敗了。
在Windows 7中,使用QProcess信號錯誤(QProcess中::的processError)後流程 - 發射>啓動(...)給我另外,QProcess :: FailedToStart
而且我測試了這個錯誤: QStringList參數; 論據< <「/ c」; 論據< <「java」; 論據< <「-jar」; 參數< <「absolute_path \ app.jar」; //我想執行的java應用程序 參數< <「-blah-blah」; //一些java程序的參數 process-> start(「cmd.exe」,arguments); 但是,然後cmd.exe抱怨沒有找到java ...
我懷疑有一些權限問題,我設置我的可執行文件作爲管理員運行,但沒有運氣,所以我已經用盡了想法...
顯然,Java安裝在Windows 7機器(手動調用它從cmd.exe工程)。
發佈到[email protected] – SunnyShah 2010-06-23 14:20:06
看起來像你的環境沒有配置。改變你的PATH環境變量以包含爲我保存java.exe的路徑,它是「C:\ Java \ JRE \ Bin」,在你的系統上找到java.exe並相應地改變這個路徑。 – 2011-02-23 12:46:33
正確配置PATH,正如我在我的問題中所說的,從命令行工作調用java(從任何位置調用它) – 2011-02-23 16:15:57