简体   繁体   English

Java执行shell命令-错误[无法运行程序“sh”:CreateProcess错误=2,系统找不到指定的文件]

[英]Java execute shell command - error [Cannot run program "sh": CreateProcess error=2, The system cannot find the file specified]

I want to execute the python script from java using shell commands file location: d:/python/test.py我想使用 shell 命令文件位置从 java 执行 python 脚本:d:/python/test.py

below is my java program下面是我的java程序

def callstme(){
        Process p
        try {

            List<String> cmdList = new ArrayList<String>();
            cmdList.add("sh");
            cmdList.add("d:/python/test.py");
            ProcessBuilder pb = new ProcessBuilder(cmdList);
            p = pb.start();

            p.waitFor();
            BufferedReader reader=new BufferedReader(new InputStreamReader(
             p.getInputStream()));
            String line;
            while((line = reader.readLine()) != null) {
                System.out.println(line);
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

while executing I'm getting the error执行时出现错误

"java.io.IOException: Cannot run program "sh": CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)

你打印错了文件名?

d:/python/test.pyy

暂无
暂无

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

相关问题 无法运行程序“ query.sh”:CreateProcess错误= 2,系统找不到指定的文件 - Cannot run program “query.sh”: 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:无法运行程序“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运行命令,但可以通过cmd运行 CreateProcess error=2, The system cannot find the file specified - Unable to run command through Java, but can run it through cmd CreateProcess error=2, The system cannot find the file specified java.io.IOException:Cannot run program &quot;sh&quot; (in directory &quot;c:\\cygwin\\bin\\test&quot;):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 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
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM