2013-03-26 31 views
2

有什麼辦法從javaservlet運行php命令行腳本(服務器端)?我一直在嘗試,我沒有得到任何異常,但腳本並沒有做它應該做的事情。我不知道我是否違反了任何安全規則(如小程序)。我正在使用此代碼:從java servlet運行命令行php腳本

Runtime runtime = Runtime.getRuntime(); 
Process process = null; 
try 
{ 
    process = runtime.exec("php " + "wsaa-client.php wsfe" + " wsfe"); 
} 
catch(Exception e) 
{ 
    out.println("<h4>Runned!</h4>"); 
} 

而且一切看起來都不錯。即使我有一個進程運行稱爲:php-cgi.exe

任何幫助/建議?

+0

你會得到什麼輸出?如果你看到'Runned!',那麼代碼可能會產生一個異常。在'out.println ...'之後立即添加'e.printStackTrace()',看看會發生什麼。 – 2013-03-26 22:17:04

回答

0

你可以嘗試使用PHP和wsaa-client.php文件的絕對路徑。 也請抓住例外並打印出例外。