[英]execute multiple commands in cmd using java
I need to execute multiple comments in single cmd window using java. 我需要使用Java在单个cmd窗口中执行多个注释。
The comments are 评论是
1. cd C:\Apps\wildfly-8.0.0.Final\bin
2. jboss-cli.bat --connect --command=\"deploy --force C:\Users\me\git\test\Test\build\libs\TestEAR.ear
Because I need to execute the second command from the folder "C:\\Apps\\wildfly-8.0.0.Final\\bin". 因为我需要从文件夹“ C:\\ Apps \\ wildfly-8.0.0.Final \\ bin”执行第二个命令。
I tried this : 我尝试了这个:
Runtime.getRuntime().exec("cmd /c start cd C:\\Apps\\wildfly-8.0.0.Final\\bin\\ && start cmd.exe /c jboss-cli.bat --connect --command=\"deploy --force C:\\Users\\me\\git\\test\\Test\\build\\libs\\TestEAR.ear\"");
But it is executing these commands separate , that is it will open one cmd window and executes the first commands , then it will execute the second command in another cmd window , and showing the error : 但是它是分开执行这些命令的,也就是说,它将打开一个cmd窗口并执行第一个命令,然后它将在另一个cmd窗口中执行第二个命令,并显示错误:
Could not locate "C:\Users\me\git\test\Test\build\libs\TestEAR.ear".
Please check that you are in the bin directory when running this script.
Press any key to continue . . .
I found some solutions with batch file , but in my application I can't use batch file (must not use batch file ) . 我找到了一些有关批处理文件的解决方案,但是在我的应用程序中,我不能使用批处理文件(必须不使用批处理文件)。
Can anyone suggest a solution ? 有人可以提出解决方案吗?
If I understand your question you could use a ProcessBuilder
and call directory(File)
. 如果我理解您的问题,则可以使用ProcessBuilder
并调用directory(File)
。 Something like 就像是
public static void main(String[] args) throws IOException {
String folder = "C:\\Apps\\wildfly-8.0.0.Final\\bin";
String command = "jboss-cli.bat --connect --command=\"deploy --force "
+ "C:\\Users\\me\\git\\test\\Test\\build\\libs\\TestEAR.ear\"";
ProcessBuilder pb = new ProcessBuilder(command);
pb.directory(new File(folder));
pb.inheritIO();
Process p = pb.start();
try {
p.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.