[英]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.