title: How to use Pipe Symbol through exec in Java
body: <p>I am using the following code to get the details of all process running in the system:</p>
  
  <pre><code>Process p = Runtime.getRuntime().exec("ps aux");
  BufferedReader stdInput = new BufferedReader(new 
               InputStreamReader(p.getInputStream()));
  BufferedReader stdError = new BufferedReader(new 
               InputStreamReader(p.getErrorStream()));
  </code></pre>
  
  <p>I want to filter <code>ps aux</code> down with the pipe symbol so I use this:</p>
  
  <pre><code>Process p = Runtime.getRuntime().exec("ps aux | grep java");
  </code></pre>
  
  <p>It goes to the ErrorStream. Later I noticed the Pipe Symbol (|) is used as Bitwise inclusive OR operator in Java. So I used backslash in front of pipe symbol as shown below:</p>
  
  <pre><code>Process p = Runtime.getRuntime().exec("ps aux \\| grep java"); 
  </code></pre>
  
  <p>But again it goes to the ErrorStream.  How can I run <code>ps aux | grep java</code> through exec in Java?</p>