2011-12-06 32 views
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(); 
} 
+0

嘗試在文件名的末尾添加'.exe'? – cHao

+0

你可以發佈試圖運行'bash'的Java代碼嗎? – hmjd

+0

D:/ cygwin/bin/bash是否存在?我有cygwin並且運行得很好,除了將bash的路徑更改爲「C:/ bin/bash」,將-c參數更改爲「-c/bin/ls -la」。 – hmjd

回答

0

作爲推薦評論添加.exe會解決這個但這樣做刪除bash.???文件。

在與bash.exeRuntime.exec()試圖執行它相同的目錄中有一個名爲bash.???(我從來沒有找到什麼擴展名是)的文件。

bash.???必須在成功執行後的某個時刻創建,因此它曾經工作過一次,然後失敗。

相關問題