简体   繁体   English

Java exec命令提示符多于一行命令

[英]Java exec command prompt more than one line of command

I have code like this : 我有这样的代码:

Runtime rt = Runtime.getRuntime();
rt.exec("C:\\test\\MyJavaApp\\winsw\\test.exe install"); // executed
rt.exec("C:\\test\\MyJavaApp\\winsw\\test.exe start"); // not executed

How to execute the second line command too? 怎样执行第二行命令呢?

Try 尝试

Runtime rt = Runtime.getRuntime();
rt.exec("C:\\test\\MyJavaApp\\winsw\\test.exe install").waitFor();
rt.exec("C:\\test\\MyJavaApp\\winsw\\test.exe start");

because according to the javadoc this will be executed in a seperate process so the rt.exec() method immediatly returns without waiting. 因为根据Javadoc,这将在单独的进程中执行,所以rt.exec()方法立即返回而无需等待。

public Process exec(String command) throws IOException Executes the specified string command in a separate process. public Process exec(String command)throws IOException在单独的进程中执行指定的字符串命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM