Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.io.IOException:Cannot run program "sh" (in directory"c:\cygwin\bin\test"):CreateProcess error=2.The system cannot find file specified

I am running shell scripts with the help of java and cygwin. When i am running my code in windows xp it works fine. Now i am trying to run same code on windows 7 i am getting above error.

(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

Why this error occurred.I have set my path for cygwin (PATH=.;c:\cygwin\bin) How to avoid this.

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());

But it is giving the output as E:\NIRAJ\example\app.sh which is in my java program. even i am setting up pb.directory to the path.

if i check System.out.print(pb.directory()); it gives me output C:\cygwin\bin\Test

like image 613
Code Hungry Avatar asked Jun 16 '26 10:06

Code Hungry


1 Answers

In PATH variable, you need to put cygwin's bin directory before any other Windows' paths.

Do this:

PATH=c:\cygwin\bin:RestWindowsPaths

Not that:

PATH=RestWindowsPathVariables:c:\cygwin\bin
like image 133
thanos.a Avatar answered Jun 18 '26 01:06

thanos.a



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!