ITPub博客

首页 > > > 检测进程是否存在无法打印出具体信息怎么办

检测进程是否存在无法打印出具体信息怎么办

作者:llittle 时间:2019-09-18 15:29:05 0 删除 编辑

Runtime.getRuntime().exec检测进程是否存在无法打印出具体信息怎么办


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等,但该程序执行后只能打印出个数,请问是哪里错了吗,该怎么写

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/813/viewspace-3170887/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-12

  • 博文量
    448
  • 访问量
    4369