title: Java exec linux command
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/5928225/how-to-make-pipes-work-with-runtime-exec">How to make pipes work with Runtime.exec()?</a>  </p>
  </blockquote>
  
  
  
  <p>Hello i wrote simple java function using exec command. This function check that font exist in system (linux). First i wrote simple bash command : <code>identify -list font | grep  -i 'Font: Times-Bold' -w</code> and its work perfectly so i create simple program: </p>
  
  <pre><code>public abstract class SystemReader{
  
      public static final void checkFontExist(String name){
              String command = "identify -list font | grep -i -w \'Font: "  + name + "\'";
              Process p  =Runtime.getRuntime().exec(command);
  
              String lines = "";
              String resoults ="";
              BufferedReader bufferedReader = new BufferedReader(new      InputStreamReader(p.getInputStream()));
              while((line  buferedReader.readLine())!=null){
                      resoult += line + "\n";
              }
  
              System.out.println("RESPONSE: " + resoult);
              bufferreader.close();
      }
  </code></pre>
  
  <p>}</p>
  
  <p>Its working but not i espect. This function return all fonts exist in my system . 
  Its seems that command grep is not exec  ?</p>
  
  <p>i try use another version of command exec() i create : </p>
  
  <pre><code>String command = {"identify -list font", "grep -i -w \'Font: " + fontName + "\'"}
  </code></pre>
  
  <p>but i have got error  :</p>
  
  <pre><code>Exception in thread "main" java.io.IOException: Cannot run program "identify -list font ": java.io.IOException: error=2, No such file or directory
      at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
      at java.lang.Runtime.exec(Runtime.java:593)
      at java.lang.Runtime.exec(Runtime.java:466)
  </code></pre>
  
  <p>Can you give me advice what is wrong ? thanks a lot </p>