我能够在Java中使用Cygwin运行shell脚本。 但是现在我收到以下消息。
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();
}