0
我能夠運行shell腳本在java中的Cygwin。但現在我得到以下信息。線程「main」異常java.io.IOException:無法運行程序「D:/ cygwin/bin/bash」:CreateProcess錯誤= 193,%1不是有效的Win32應用程序
Exception in thread "main" java.io.IOException: Cannot run program "D:/cygwin/bi
n/bash": CreateProcess error=193, %1 is not a valid Win32 application
如何避免此異常?
代碼
{
String cmd;
cmd = "D:/cygwin/bin/bash -c'/bin/ls -la'";
System.out.println("EXECING: " + cmd);
p = Runtime.getRuntime().exec(cmd);
in = p.getInputStream();
br = new BufferedReader(new InputStreamReader(in));
System.out.println("OUT:");
while ((line = br.readLine()) != null) {
System.out.println(line);
}
in = p.getErrorStream();
br = new BufferedReader(new InputStreamReader(in));
System.out.println("ERR:");
while ((line = br.readLine()) != null) {
System.out.println(line);
}
System.out.println();
}
嘗試在文件名的末尾添加'.exe'? – cHao
你可以發佈試圖運行'bash'的Java代碼嗎? – hmjd
D:/ cygwin/bin/bash是否存在?我有cygwin並且運行得很好,除了將bash的路徑更改爲「C:/ bin/bash」,將-c參數更改爲「-c/bin/ls -la」。 – hmjd