title: How to Execute Core Show channels Command in java and also grep Channels in it
body: <p>I would like a help from u all .I am using java and i want to execute the a command that is use to get the channels details in asterisk. the system is linux based.
  I want to execute command "core show channels" at the same time  want to grep channels also</p>
  
  <p>Following is the command and the output when fire normally in console.</p>
  
  <pre><code>   asterisk -vvvvvrx 'core show channels' | grep channels
  </code></pre>
  
  <p>and the output is 
  2 active channels</p>
  
  <p>I am trying to use following code in java</p>
  
  <pre><code>import java.io.IOException;
  import java.util.*;
  import java.io.BufferedReader;
  import java.io.InputStreamReader;
  public class ProcessBuilderExample
  {
    public static void main(String[] args) 
    throws IOException, InterruptedException
    {
    String[] commands = new String[]{"asterisk","-rx","core show channels","| grep 'channels'"};
   Process p = Runtime.getRuntime().exec(commands);
      p.waitFor();
     BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
     String line = "";
  while((line = br.readLine()) != null) {
        System.out.println(line);
  }
      System.out.println("hello");
    }
  }
  </code></pre>
  
  <p>but it is not showing me the correct output pls help me to solve this problem</p>