嘿,我正在尝试更改目录,然后使用参数运行我的命令。
final String path = "\\Local// Apps\\IBM\\SDP\\scmtools\\eclipse";
final String command = "scm help";
final String dosCommand = "cmd /c \"" + path + "\"" + command;
final Process process = Runtime.getRuntime().exec(dosCommand);
final InputStream in = process.getInputStream();
int ch;
while((ch = in.read()) != -1) {
System.out.print((char)ch);
}
它运行没有错误,但没有输出任何内容。但是,这是完成后显示的内容:
<terminated, exit value: 0>C:\Local Apps\IBM\SDP\jdk\bin\javaw.exe (Jul 22, 2019, 11:21:37 AM)
预期的输出应该是:
那我这样做正确吗?
正如安德烈亚斯所建议的
Process p = null;
ProcessBuilder pb = new ProcessBuilder("scm.exe");
pb.directory(new File("C:/Local Apps/IBM/SDP/scmtools/eclipse"));
p = pb.start();
我收到以下错误:
无法运行程序“scm.exe”(在目录“C:\Local Apps\IBM\SDP\scmtools\eclipse”中):CreateProcess error=2,系统找不到指定的文件
繁星淼淼
相关分类