2
我需要從集成測試中終止Windows(WindowsXP 32bit)上的外部進程。我以爲我只是使用'taskkill.exe',但我似乎無法得到它的工作。基本上,每次我從java中啓動一個'taskkill.exe'進程時,它會返回退出值-1073741515,但是沒有任何內容被打印到std錯誤/輸出。無法使用java進程中的taskkill.exe
要重現我寫了這個簡單的應用程序的問題:
public static void main(String[] args) throws Exception {
ProcessBuilder builder = new ProcessBuilder();
//In my real code, I kill process by its pid. However below also shows the problem:
builder.command("taskkill.exe", "/?");
builder.redirectErrorStream(true);
Process p = builder.start();
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = r.readLine();
System.out.println("out:");
while(line != null) {
System.out.println(line);
line = r.readLine();
}
System.out.println(p.waitFor());
}
更多的數據點:
- -1073741515顯然意味着 「應用程序未能正確初始化」。雖然對我不是很有幫助;)
- 我試過一堆taskkill.exe參數的組合;我試着用'cmd','/ c'作爲前綴。症狀是完全一樣的
- 我試圖執行其他windows程序,生活在windows \ system32下,我也得到-10737 ...
- 執行像'dir'或'echo'這樣的東西沒問題。
任何提示可能是什麼問題?
我能夠用您的代碼終止進程 - builder.command(「taskkill.exe」,「/ pid」,「2888」); ,我在控制檯上得到了這個消息 - out: SUCCESS:PID 2888的過程已經終止。 0 – Mohsin