50,528
社区成员
发帖
与我相关
我的任务
分享
import java.io.IOException;
import java.io.InputStream;
public class RuntimeTest {
public void runbat(String batName){
Runtime rt = Runtime.getRuntime();
Process ps = null;
try {
ps = rt.exec("cmd.exe /c start " + batName);
InputStream in = ps.getInputStream();
int c;
while ((c = in.read()) != -1) {
System.out.print(c);// 如果你不需要看输出,这行可以注销掉
}
in.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
public static void main(String[] args) throws InterruptedException {
RuntimeTest test1 = new RuntimeTest();
String batName = "D:\\apache-tomcat-8.0.21\\bin\\startup.bat";
test1.runbat(batName);
System.out.println("main thread");
}
}