2017-07-20 35 views
0

我再次發動E4應用內安裝爲someProgram.exe的E4應用程序使用問題從另一個Java應用程序啓動的E4 RCP EXE與參數數量 - WindowsOS

調用Runtime.getRuntime()EXEC(」 someProgram.exe_path「);

這確實會啓動someProgram.exe,但是當用戶在someProgram.exe應用程序中啓動任何交互時,它將變得無響應,掛起和/或凍結。 我已經用ProcessBuilder和「Runtime exec」試過了,在這兩種情況下,someProgram.exe都會掛起。我試過Runtime.getRuntime()。exec(「someProgram.exe_path」)的調用。從一個帶有靜態主函數的簡單Java類和someProgram.exe啓動並按預期完美工作,沒有掛起和正常的響應時間。

另外,我們使用

Desktop.getDesktop()打開(someProgram.exe_file)。

哪個啓動了一些程序完美沒有問題,但我們想發送一個參數與someProgram.exe和桌面的啓動請求,不幸的是不能提供該功能。另外,當使用掛起的「Runtime exec」方法時,如果我退出了在someProgram.exe上調用「Runtime exec」的程序,那麼someProgram.exe開始工作得很好,並且所有的掛起停止。另外,如果我在進程中放入「Runtime exec」調用,使用「Runtime exec」啓動睡眠線程,然後銷燬該進程,然後someProgram.exe退出。

想知道如果E4 RCP應用程序(或someProgram.exe)在應用程序的「啓動」或someProgram.exe的應用程序生命週期中發生了某種情況,該程序在另一個程序調用「Runtime exec」時不會放開在上面?或者,如果調用應用程序需要以另一種方式調用Runtime以允許它實質上釋放控制權,因爲此進程的控制似乎不會返回到啓動程序以完成其過程。

或者如果有另一種方法來實現這個啓動somePrograme.exe與Args的工作,而不會掛起。

就像我說的,someProgram.exe只在使用進程,ProcessBuilder或「Runtime exec」從另一個RCP應用程序啓動時掛起。調用「Runtime exec」的Java類可以正常工作。 Desktop.open()也很好。

在此先感謝您的建議。上的ProcessBuilder

  • 馬福

回答

0

這個問題的解決是使用inheritIO()方法:

ProcessBuilder pb = new ProcessBuilder(commands).inheritIO(); 

同樣有效辦法是使用:

pb.redirectInput(Redirect.INHERIT); 
pb.redirectOutput(Redirect.INHERIT); 
  • 希望這有助於他人在未來。

從Java文檔:

inheritIO 
public ProcessBuilder inheritIO() 
Sets the source and destination for subprocess standard I/O to be the same as those of the current Java process. 
This is a convenience method. An invocation of the form 

pb.inheritIO() 

behaves in exactly the same way as the invocation 

pb.redirectInput(Redirect.INHERIT) 
    .redirectOutput(Redirect.INHERIT) 
    .redirectError(Redirect.INHERIT) 

This gives behavior equivalent to most operating system command interpreters, or the standard C library function system(). 
Returns: 
this process builder 
Since: 
1.7 
相關問題