0

I'm trying execute this:

    Process p = Runtime.getRuntime().exec("ps -ef | grep bash");

    BufferedReader r =  new BufferedReader(new InputStreamReader(p.getInputStream()));
    while ((line = r.readLine()) != null) {
      System.out.println(line);
    }

and want see some lines, but it return Null.

If I execute just "ps -ef" it return all process correct.

Generally I need to send keyword to method, that return work process or not

Kirill_code
  • 129
  • 1
  • 9

1 Answers1

1

This will work

String[] command =  {"/bin/sh", "-c", "ps -ef | grep bash"};
Process p = Runtime.getRuntime().exec(command);
pvpkiran
  • 25,582
  • 8
  • 87
  • 134