我試圖遠程執行一個.bat文件和執行的代碼下面幾行後卡住:while循環的ProcessBuilder得到得到一個錯誤
ProcessBuilder processBuilder = new ProcessBuilder(command);
final Process process = processBuilder.start();
InputStream stderr = process.getErrorStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);
String line = null;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
process.waitFor();
System.out.println("Waiting ...");
System.out.println("Returned Value :" + process.exitValue());
,但我的程序卡住內。 它顯示的錯誤是:
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
它永不熄滅的同時loop.But它成功地執行腳本。 任何形式的幫助表示讚賞。謝謝
或者,調用'processBuilder.redirectErrorStream(true);'將進程的標準錯誤重定向到它的標準輸出。那麼你只需要從'process.getInputStream()'讀取。 – 2010-09-27 22:02:27