Java と cygwin を使用してシェル スクリプトを実行しています。Windows XP でコードを実行すると、問題なく動作します。今、私はWindows 7で同じコードを実行しようとしていますが、上記のエラーが発生しています。
(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
このエラーが発生した理由.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