[英]Java Runtime : process launched by window does not open
我正在使用glassfish服務器運行Java Web應用程序(在Windows 7 64bits,jdk 1.7.0.67上)。 我正在嘗試從一堂課上推膩子。 該過程已啟動(我可以在Windows的任務管理器中看到它),但是沒有打開膩子窗口...我嘗試了類似的代碼:
Process p = Runtime.getRuntime().exec( "rundll32 SHELL32.DLL,ShellExec_RunDLL " + "C:\\putty.exe");
要么
Process p = Runtime.getRuntime().exec("C:\\putty.exe");
要么
Process p = Runtime.getRuntime().exec(cmd /c start C:\\putty.exe");
Glassfish中的安全管理器已禁用。 putty.exe被標記為以管理員身份執行。 該方法與其他應用程序相同:cmd.exe或pspade.exe。 如果我在應用程序啟動的cmd.exe中執行代碼,則代碼執行得很好。 我不知道,您的幫助會很好!
編輯
在這種情況下不起作用,但在其他情況下可能會有所幫助。
嘗試添加:
try (BufferedReader reader = new BufferedReader(new inputStreamReader(process.getInputStream()));){
while (reader.readLine() != null){
// consume the InputStream of the shell command
} catch (IOException e) {
//might throw an Exception if reader is not closed properly
}
在exec()命令之后。 也許膩子會向控制台輸出一些信息,當緩沖區已滿時,Shell將停止執行程序。 因此,如果InputStream
未被正確使用,則外殼程序將僅等待並不執行任何操作,而是啟動進程。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.