一劲藐、應(yīng)用cmd打開一個文件
Process process = null;
String resumePath=" E:/temp/aaa.html";
try {
process = Runtime.getRuntime().exec("cmd /k start"+resumePath);
} catch (IOException e) {
e.printStackTrace();
}
二、應(yīng)用cmd運行程序
1)執(zhí)行運行node.js命令
Process process = null;
String comand58 ="cmd.exe /k start node E:\\bootside-crawler\\58index.js";
ListprocessList = new ArrayList();
try {
//Thread.sleep(5000);
//process = Runtime.getRuntime().exec("/root/2.sh"); ?傳參時需要用空格隔開
process = Runtime.getRuntime().exec(comand58+""+canshu);
BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = "";
while ((line = input.readLine()) != null ) {
processList.add(line);
}
input.close();
} catch (IOException e) {
e.printStackTrace();
}
for (String line : processList) {
//if (line.indexOf("nginx") <0)
//logger.info(line);
}
2)運行exe程序
Process process = null;
//E:\\node\\node.js 需要打開文件的位置
String comand ="cmd.exe /k start ?E:\\node\\node.js";
ListprocessList = new ArrayList();
try {
//Thread.sleep(5000);
process = Runtime.getRuntime().exec(comand);
BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = "";
while ((line = input.readLine()) != null) {
processList.add(line);
}
input.close();
} catch (IOException e) {
e.printStackTrace();
}