你好,我试着在eclipse中运行下面的cmd代码:
"DIR \""+DEV_HOME+"\\src\"\\*.java /b /s >> \""+DEV_HOME+"\\bin\\javaFiles.txt\""在clear中,它看起来像这样:
DIR "D:\Thomas\Dokumente\Daten\workspace\WBRLight\src"\*.java /b /s >> "D:\Thomas\Dokumente\Daten\workspace\WBRLight\bin\javaFiles.txt"但我得到以下错误消息:
java.io.IOException: Cannot run program "dir": CreateProcess error=2, Das System kann die angegebene Datei nicht finden
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1041)
at java.lang.Runtime.exec(Runtime.java:617)
at java.lang.Runtime.exec(Runtime.java:450)
....当我尝试使用cmd框中的代码时,它工作得很好。我的代码:
public void run_cmdLine(String command) {
try {
Runtime rt = Runtime.getRuntime();
BufferedReader input = null;
Process pr = null;
pr = rt.exec(command);
input = new BufferedReader(new inputStreamReader(pr.getInputStream()));
String line = null;
while ((line = input.readLine()) != null) {
System.out.println(line);
}
int exitVal = pr.waitFor();
System.out.println("Exited with error code " + exitVal);
} catch (Exception e) {
System.out.println(e.toString());
e.printStackTrace();
}
}发布于 2014-01-22 19:23:42
在命令字符串的开头添加"cmd.exe /c",这应该可以解决问题。
/c参数将完成cmd并将其返回给Java进程。
如果没有它,进程将挂起。
https://stackoverflow.com/questions/21281354
复制相似问题