简体   繁体   English

以参数结尾的Execute命令以:error = 2结尾,系统找不到指定的文件

[英]Execute command with arguments ends with: error=2, The system cannot find the file specified

I have some trouble with my code to run a program on Windows command line. 我的代码在Windows命令行上运行程序时遇到一些麻烦。 My intension is to update a version control repository with the svn.exe. 我的目的是使用svn.exe更新版本控制存储库。 This program needs the update -u parameter and the path to the repository (eg C:\\Projects\\Reposirtory). 该程序需要update -u参数和存储库的路径(例如C:\\ Projects \\ Reposirtory)。 When I execute the code as seen below I get this error: 当我执行如下所示的代码时,出现此错误:

Cannot run program "C:\\Program Files\\SlikSvn\\bin\\svn status -u "C:\\Projects\\Reposirtory"": CreateProcess error=2, The system cannot find the file specified 无法运行程序“ C:\\ Program Files \\ SlikSvn \\ bin \\ svn status -u“ C:\\ Projects \\ Reposirtory”“:CreateProcess错误= 2,系统找不到指定的文件

public void checkUpdates(String baseDir)
    {
        StringBuilder sb = new StringBuilder();

        try
        {

            ProcessBuilder pb = new ProcessBuilder("C:\\Program Files\\SlikSvn\\bin\\svn status -u \"C:\\Projects\\\"");

            pb.redirectErrorStream(true);
            Process process = pb.start();
            BufferedReader inStreamReader = new BufferedReader(
                    new InputStreamReader(process.getInputStream()));

            while (process.isAlive() == true)
            {
                this.wait(3);
            }
            while (inStreamReader.ready() == true)
            {
                sb.append(inStreamReader.readLine());
            }

            System.out.println(sb.toString());
        }
        catch (IOException e1)
        {
            System.out.println("Es ist ein Fehler aufgetreten. " + e1.getMessage());
        }
        catch (Exception e)
        {
            System.out.println("Es ist ein Fehler aufgetreten. " + e.getMessage());
        }
        finally
        {
        }
    }

When I only execute this code, it will works. 当我仅执行此代码时,它将起作用。

ProcessBuilder pb = new ProcessBuilder("C:\\Program Files\\SlikSvn\\bin\\svn");

The solution is the comment from laune. 解决的办法是劳恩的评论。 The arguments have to stand in separate strings. 参数必须位于单独的字符串中。

ProcessBuilder pb = new ProcessBuilder("C:\\Program Files\\SlikSvn\\bin\\svn", "status", "-u", "\"" +baseDir +"\"");

It's not C:\\\\Program Files\\\\SlikSvn\\\\bin\\\\svn . 不是C:\\\\Program Files\\\\SlikSvn\\\\bin\\\\svn It's "C:\\\\Program Files\\\\SlikSvn\\\\bin\\\\svn.exe" . 它是"C:\\\\Program Files\\\\SlikSvn\\\\bin\\\\svn.exe" Note the extension and quotes around the path to the executable. 注意可执行文件路径的扩展名和引号。

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

相关问题 Java执行shell命令-错误[无法运行程序“sh”:CreateProcess错误=2,系统找不到指定的文件] - Java execute shell command - error [Cannot run program "sh": CreateProcess error=2, The system cannot find the file specified] 错误已更改,系统找不到指定的文件 - Error changed system cannot find file specified CreateProcess error=2 系统找不到指定的文件 - CreateProcess error=2 The system cannot find the file specified CreateProcess error=2, 系统找不到指定的文件 - CreateProcess error=2, The system cannot find the file specified Java 系统在尝试执行时找不到指定的文件 - Java system cannot find file specified when trying to execute 无法通过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 该系统找不到指定的文件? - The system cannot find the file specified? 系统找不到指定的文件 - The system cannot find the specified file 错误信息:createProcess error=2,系统找不到指定的文件 - Error message: createProcess error=2, The system cannot find the file specified signing.properties错误(系统找不到指定的文件) - signing.properties Error (The system cannot find the file specified)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM