【发布时间】:2013-06-08 23:58:58
【问题描述】:
我运行 cmd(命令行)并以这种方式从 Java 运行我的批处理文件:
final String cmd = "cmd /c C: && dir && cd C:\MyApp\Maxi && dir && C:\MayApp\Maxi\deploy.bat";
try {
Process process = Runtime.getRuntime().exec(cmd);
final InputStream in = process.getInputStream();
int ch;
while((ch = in.read()) != -1) {
System.out.print((char)ch);
}
} catch (IOException e) {
System.out.println("IOException on CMD executing statement");
e.printStackTrace();
}
它运行成功,但是我修改了批处理文件并添加了一些参数,所以我必须将名称传递给批处理文件,所以我尝试了这个: (我发送“Name1”作为参数)
final String cmd = "cmd /c C: && dir && cd C:\MyApp\Maxi && dir && C:\MayApp\Maxi\deploy.bat Name1";
try {
Process process = Runtime.getRuntime().exec(cmd);
final InputStream in = process.getInputStream();
int ch;
while((ch = in.read()) != -1) {
System.out.print((char)ch);
}
} catch (IOException e) {
System.out.println("IOException on CMD executing statement");
e.printStackTrace();
}
但它现在不工作并且命令没有执行。我只得到“dir”命令输出。
谁能帮忙?
注意:命令在 CMD 上成功运行,但在 java.
【问题讨论】:
标签: java command-line batch-file cmd command-line-arguments