Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java.io.IOException:无法运行程序“sh”(在目录“c:\cygwin\bin\test”中):CreateProcess error=2。系统找不到指定的文件_Java_Cygwin_Cygpath - Fatal编程技术网

java.io.IOException:无法运行程序“sh”(在目录“c:\cygwin\bin\test”中):CreateProcess error=2。系统找不到指定的文件

java.io.IOException:无法运行程序“sh”(在目录“c:\cygwin\bin\test”中):CreateProcess error=2。系统找不到指定的文件,java,cygwin,cygpath,Java,Cygwin,Cygpath,我在java和cygwin的帮助下运行shell脚本。当我在WindowsXP中运行我的代码时,它工作正常。现在我正试图在Windows7上运行相同的代码,我发现了上面的错误 (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

我在java和cygwin的帮助下运行shell脚本。当我在WindowsXP中运行我的代码时,它工作正常。现在我正试图在Windows7上运行相同的代码,我发现了上面的错误

(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.printpb.directory;它给我输出C:\cygwin\bin\Test

首先尝试获取指定文件的路径,以确保它:

我不太确定,但这可能会让你领先一步:

File file = new File("app.sh");//File name with extension
System.out.println(file.getCanonicalPath());
这应该打印:c:\cygwin\bin\test 也可以这样使用分隔符:c:\\cygwin\\bin\\test

希望这有帮助

更新


首先尝试首先获取指定文件的路径,以确保:

我不太确定,但这可能会让你领先一步:

File file = new File("app.sh");//File name with extension
System.out.println(file.getCanonicalPath());
这应该打印:c:\cygwin\bin\test 也可以这样使用分隔符:c:\\cygwin\\bin\\test

希望这有帮助

更新


在任何windows路径声明之前,必须将cygwin的bin目录添加到PATH环境变量中

PATH=c:\cygwin\bin:RestWindowsPathVariables

在任何windows路径声明之前,必须将cygwin的bin目录添加到PATH环境变量中

PATH=c:\cygwin\bin:RestWindowsPathVariables

尝试使用管理员权限运行i。使用管理员权限启动命令行,然后从命令行运行java或使用权限启动IDE。测试是您的文件还是目录?@programmer_1:test是我的目录。在此目录中app.sh是shell脚本文件。请使用管理员权限尝试运行i。使用管理员权限启动命令行,然后从命令行运行java或使用权限启动IDE测试是您的文件还是目录?@programmer_1:test是我的目录。在这个目录中app.sh是shell脚本文件。由于您的app.sh位于示例目录中,您希望它在测试中运行,因此它将如何运行?此外,您还应使用cygbin.exe运行命令,如下所示:cygbin.exe PATH/app.sh假定cygbin是您的可执行文件。我正在将所有必需的文件复制到测试文件夹。然后设置pb.directorynew文件c:\\cygwin\\bin\\Test\\;然后执行该命令,它在windows xp下工作正常。CYGWIN\u NT-6.1-WOW64 1.7.90.237/5/3让我们看看它将如何运行,因为您的app.sh位于示例目录中,并且您希望它在测试中运行?此外,您还应使用cygbin.exe运行命令,如下所示:cygbin.exe PATH/app.sh假定cygbin是您的可执行文件。我正在将所有必需的文件复制到测试文件夹。然后设置pb.directorynew文件c:\\cygwin\\bin\\Test\\;然后执行命令,它就可以在windows xp中正常工作了。CYGWIN\u NT-6.1-WOW64 1.7.90.237/5/3让我们