我運行shell腳本的幫助下java和cygwin。當我在Windows XP中運行我的代碼時,它工作正常。現在我試圖在Windows 7上運行相同的代碼,我得到的錯誤以上。產生java.io.IOException:不能運行程序「SH」(在目錄「C: cygwin的斌測試」):CreateProcess的錯誤= 2,系統找不到指定文件
(java.io.IOException)java.io.IOException:
Cannot run program "sh" (in directory"c:\cygwin\bin\test"):
CreateProcess error=2.The system cannot find file specified
爲什麼這個錯誤occurred.I已設置我的路徑的cygwin (PATH=.;c:\cygwin\bin)
如何避免這種情況。
ProcessBuilder pb = new ProcessBuilder();
pb.directory(new File("C:\\cygwin\\bin\\Test\\"));
File shellfile = new File("app.sh");//File name with extension
System.out.println(shellfile.getCanonicalPath());
但它給出的輸出爲E:\NIRAJ\example\app.sh
這是在我的Java程序。即使我將pb.directory設置爲路徑。
如果我檢查System.out.print(pb.directory());
它給了我輸出C:\cygwin\bin\Test
嘗試以管理員權限運行我。啓動命令行用管理員權限,然後運行命令行的Java(或先從您的權利IDE) – Hurda 2012-02-23 08:41:48
因此,測試您的文件或目錄? – Ved 2012-02-23 08:49:52
@ programmer_1:測試是我directory.inside這個目錄app.sh是shell腳本文件 – 2012-02-23 08:52:25