我运行 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 中无法运行。