我目前正在开发一个应该执行一些控制台命令的程序。
我的代码如下所示:
private String executeCommands(String[] commands)
{
String result = "";
try
{
ProcessBuilder pb = new ProcessBuilder();
String s = null;
Charset charset = Charset.forName("IBM850");
BufferedReader stdInput;
Process proc;
for (String command : commands)
{
System.out.println("Ausfuehrung von: " + command);
pb.command(command);
proc = pb.start();
stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream(), charset));
while ((s = stdInput.readLine()) != null)
{
result += s;
}
System.out.println();
}
}
catch (Exception ex)
{
result = ex.getMessage();
}
return result;
}
private void userLogIn(IUserInteraction userInteraction)
{
String[] command = { "svn auth --show-passwords" };
String result = executeCommands(command);
System.out.println(result);
}
输出是“无法运行程序“svn auth --show-passwords”:错误=2,没有这样的文件或目录”,但是当我在控制台中手动输入命令时,它起作用了。我做错了什么?
提前致谢!
慕尼黑8549860
喵喔喔
相关分类