67,515
社区成员
发帖
与我相关
我的任务
分享
public static void command() {
//String cmd = "cmd /c start *.exe";
String cmd = "*.exe";
System.out.println("正在执行命令:"+cmd);
try {
Runtime rt = Runtime.getRuntime();
Process p = rt.exec(cmd);
p.destroy();
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream(), "gbk"));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
br = new BufferedReader(new InputStreamReader(p.getErrorStream(), "gbk"));
while ((line = br.readLine()) != null) {
System.err.println(line);
}
//int exitVal = p.waitFor();
//System.out.println("执行完毕!返回值="+exitVal);
System.out.println("执行完毕!返回值");
} catch (Exception e) {
e.printStackTrace();
}
}