问题描述
- java 在linux 下调用 SH 文件 在windows 下调用 bat 执行后不能 看见进程
-
-
public boolean execCmd(String[] cmds){Process p = null;Runtime rt = Runtime.getRuntime();BufferedReader in = null;InputStreamReader reader = null;try { p = rt.exec(cmds); InputStream info = p.getInputStream(); in = new BufferedReader(new InputStreamReader (info)); System.out.println(""exec info : "" + in.readLine());} catch (IOException e) { e.printStackTrace(); return false;} finally{ close(in reader p);}return true;
}
- private void close(BufferedReader in InputStreamReader reader Process p){
try {
if(in != null){
in.close();
in = null;
}
if(reader != null){
reader.close();
reader = null;
}
if(p != null){
p.waitFor();
p.destroy();
p = null;
}
} catch (Exception e) {
e.printStackTrace();
}
}
-
解决方案
bat在cmd.exe或者explorer.exe
时间: 2025-01-21 06:44:01