title: Executing Fabric Script through JAVA
body: <p>I have this simple fab script and I want to execute this through JAVA:</p>
  
  <pre><code>    from __future__ import with_statement
      from fabric.api import *
      from fabric.contrib.console import confirm
      env.hosts = ['localhost']
  
      def updatefile():
       with shell_env(TERM='vt100'):
      with cd('/Users/'):
      run("pwd")
      run("ls -l")
  
      def execute():
        updatefile()
  </code></pre>
  
  <p>When I execute this script from command line it works : fab -f test.py executes but I want to execute via java.  Tried with ..</p>
  
  <pre><code>public class ExecuteScript {
  
  @Test
  public void testExecuteScript() throws NumberFormatException, IOException{
  
      StringBuffer output = new StringBuffer();
      Process p;
      try {
          p = Runtime.getRuntime().exec("fab -f src/test/resources/scripts/test.py execute");
          p.waitFor();
          BufferedReader reader = 
                  new BufferedReader(new InputStreamReader(p.getInputStream()));
  
          String line = "";           
          while ((line = reader.readLine())!= null) {
              output.append(line + "\n");
          }
  
      } catch (Exception e) {
          e.printStackTrace();
      }
      System.out.println(output.toString());
  }
  }   
  </code></pre>
  
  <p>It doesn't work.. looked at the documentation for java examples in <a href="http://fabric8.io/gitbook/quickstarts.html" rel="nofollow">http://fabric8.io/gitbook/quickstarts.html</a> the links are broken. </p>