简体   繁体   English

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

[英]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.我在 java 和 cygwin 的帮助下运行 shell 脚本。 When i am running my code in windows xp it works fine.当我在 windows xp 中运行我的代码时,它工作正常。 Now i am trying to run same code on windows 7 i am getting above error.现在我正在尝试在 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

Why this error occurred.I have set my path for cygwin (PATH=.;c:\\cygwin\\bin) How to avoid this.为什么会发生此错误。我已为 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());

But it is giving the output as E:\\NIRAJ\\example\\app.sh which is in my java program.但它给出的输出为E:\\NIRAJ\\example\\app.sh ,它在我的 Java 程序中。 even i am setting up pb.directory to the path.即使我正在将 pb.directory 设置为路径。

if i check System.out.print(pb.directory());如果我检查System.out.print(pb.directory()); it gives me output C:\\cygwin\\bin\\Test它给了我输出C:\\cygwin\\bin\\Test

In PATH variable, you need to put cygwin's bin directory before any other Windows' paths.在PATH变量,你需要把Cygwin的bin目录下的任何其他Windows的路径之前

Do this:做这个:

PATH=c:\cygwin\bin:RestWindowsPaths

Not that:不是那个:

PATH=RestWindowsPathVariables:c:\cygwin\bin

First try to get the path of specified file first to ensure it:首先尝试先获取指定文件的路径以确保它:

I am not much sure but this may lead you one step ahead :我不太确定,但这可能会让你领先一步:

File file = new File("app.sh");//File name with extension
System.out.println(file.getCanonicalPath());

This should print : c:\\cygwin\\bin\\test Also use separator like this instead : c:\\\\cygwin\\\\bin\\\\test这应该打印: c:\\cygwin\\bin\\test也使用这样的分隔符: c:\\\\cygwin\\\\bin\\\\test

Hope this helps.希望这可以帮助。

UPDATE更新

String myCommand = "c:\\cygwin\\bin\\test\\cygbin";
String myArg = PATH_TO_shellscript+"app.sh";
ProcessBuilder p = new ProcessBuilder(myCommand, myArg).start();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.io.IOException:无法运行程序“。\\ bin \\ catalina.bat”-CreateProcess错误= 2,系统找不到指定的文件 - java.io.IOException: Cannot run program “.\bin\catalina.bat” - CreateProcess error=2, The system cannot find the file specified java.io.IOException:无法运行程序“plink”:CreateProcess error=2,系统找不到指定的文件 - java.io.IOException: Cannot run program "plink": CreateProcess error=2, The system cannot find the file specified java.io.IOException:无法运行程序“sqlldr”:CreateProcess error = 2,系统找不到指定的文件 - java.io.IOException: Cannot run program “sqlldr”: CreateProcess error=2, The system cannot find the file specified java.io.IOException:无法运行程序“ WMIC”:CreateProcess错误= 2,系统找不到指定的文件 - java.io.IOException: Cannot run program “WMIC”: CreateProcess error=2, The system cannot find the file specified java.io.IOException:无法运行程序“ tskill”:CreateProcess错误= 2,系统找不到指定的文件 - java.io.IOException: Cannot run program “tskill”: CreateProcess error=2, The system cannot find the file specified java.io.IOException:无法运行程序“mysql”:CreateProcess error=2,系统找不到指定的文件 - java.io.IOException:Cannot run program “mysql”:CreateProcess error=2, The system cannot find the file specified java.io.IOException:无法运行程序“”:CreateProcess error = 2,系统找不到指定的文件 - java.io.IOException: Cannot run program “”: CreateProcess error=2, The system cannot find the file specified java.io.IOException:无法运行程序“/usr/bin/sh”:java.io.IOException:error=2,没有那个文件或目录 - java.io.IOException: Cannot run program “/usr/bin/sh”: java.io.IOException: error=2, No such file or directory e:java.io.IOException:无法运行程序“ java -jar bg.jar”:CreateProcess错误= 2,系统找不到文件 - e: java.io.IOException: Cannot run program “java -jar bg.jar”: CreateProcess error=2, The system cannot find the file 引起:java.io.IOException:CreateProcess error = 2,系统找不到AWS指定的文件 - Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified with AWS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM