String[] cmd = {"/bin/sh", "-c", "ps -ef |grep " + s };//s是参数,进程名
Process proc = Runtime.getRuntime().exec(cmd);
BufferedReader br = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line = null;
if ((line = br.readLine()) == null) {
XxlJobLogger.log("执行出错");
log.info("执行出错");
return new ReturnT<>(ReturnT.FAIL_CODE,"执行出错");
} else {
int count=0;
do {
XxlJobLogger.log(s + ":" + line);
count++;
} while ((line = br.readLine()) != null);
}
br.close();
在linux上同样的命令会打印出进程的具体信息包括pid,command等,但该程序执行后只能打印出个数,请问是哪里错了吗,该怎么写
三年都没有评论,大佬给我解决了。String[] cmd_findNginxProcessAndKill_Array = new String[]{"/bin/sh","-c",cmd_findNginxProcessAndKill}; //我是ps 命令不起作用,用这个就可以了。
– 丁大憨憨 3年前