执行Linux或者Window下的命令的代码:
public static void runbat(String batFilePath) {
if(System.getProperty("os.name").toUpperCase().contains("WIN")){
//不做任何处理
}else{
batFilePath="sh "+batFilePath;
}
try {
Process ps = Runtime.getRuntime().exec(batFilePath);
InputStream is = ps.getInputStream();
int c;
while ((c = is.read()) != -1) {
// System.out.println("执行成功 " + c);
}
is.close();
} catch (Exception e) {
e.printStackTrace();
}
}
时间: 2024-11-01 19:09:14