title: bash unix processbuilder from java not running
body: <p>I want to execute a simple Unix command from my Java servlet: what I need to do is a simple echo write to file like this one:</p>
  
  <pre><code>echo HELLO &gt; myfile.txt
  </code></pre>
  
  <p>What I'm doing in my servlet is:</p>
  
  <pre><code>import java.io.IOException;
  import java.io.PrintWriter;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  public class ServletAutorecovery extends HttpServlet {
      protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          response.setContentType("text/html;charset=UTF-8");
          PrintWriter out = response.getWriter();
          try {
              ProcessBuilder pb = new ProcessBuilder("/usr/bin/bash", "-c", "echo HELLO &gt; ../webapps/test/myfile.txt");
              pb.start();
          } finally { 
          out.close();
      }
  
      @Override
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          processRequest(request, response);
      }
  
      @Override
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          processRequest(request, response);
      }
  }
  </code></pre>
  
  <p>My problem is: this code section is not giving me any errors, but nothing happens. After I executed my servlet, the file has not being created, and of course, nothing is written in it.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>EDIT1: added full path to pb command.</p>
  
  <p>EDIT2: <code>bash</code> is in the path <code>/usr/bin/bash</code>, 100% sure of it.</p>
  
  <p>EDIT3: added SSCCE.</p>