String command = "ps -ef";
        Process child = Runtime.getRuntime().exec(command);
        InputStream in = child.getInputStream();
        int c;
        StringBuilder sb = new StringBuilder();
        while ((c = in.read()) != -1) {
         sb.append((char)c);
        }
        in.close();
        System.out.println(sb.toString());这样是可以有返回信息的,但是只要把command = "ps -ef";变为"ps -ef|grep java";就没有任何返回信息了,貌似加|参数后就会出现这个问题,求解。

解决方案 »

  1.   

    ps -ef返回系统进程
    ps -ef|grep java  返回系统进程中名字带有“java”字符串的进程
    没有返回信息说明系统没有名字带有“java”的进程.................................
      

  2.   

    在linux下面直接ps -ef|grep java 是有返回值的,但用java代码调用就没返回了。。我怀疑是java调用linux命令的时候参数有什么讲究
      

  3.   

    If an argument contain spaces, it is necessary to use the overload that requires the command and its arguments to be supplied in an array: 具体你看看这个,也许会有帮助
    http://blog.csdn.net/pengchua/archive/2010/03/08/5357607.aspx