title: running linux command from java, error 500, Cannot run program No such file or directory
body: <p>im trying to send an email with a Linux command from Java, i admit i don't know much about Linux but i think iv'e tried everything and i'm just really confused, if someone could shed some light for it would be great</p>
  
  <p>i export the application to a war file and upload it to a linux server (CentOS)</p>
  
  <p>so here's what i'm doing: i'm triggering the code from a servlet with the browser</p>
  
  <pre><code>protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  
      String cmd = "mail -s \"Test Email\" my@email.com &lt; /usr/share/apache-tomcat-7.0.42/webapps/slots_dashboard/alert_mail.txt";
  
      //String cmd = "whoami"; //returns tomcat
  
      ProcessBuilder pb = new ProcessBuilder(cmd);
      Process proc = pb.start();
  
      BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream()));
  
      BufferedReader stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
  
      String s = null;
  
      while ((s = stdInput.readLine()) != null) {
          resp.getWriter().println(s);
      }
  
      while ((s = stdError.readLine()) != null) {
          resp.getWriter().println(s);
      }
  }
  </code></pre>
  
  <p>the error i get is:
  HTTP Status 500 - Cannot run program "mail -s "Test Email" my@email.com &lt; /usr/share/apache-tomcat-7.0.42/webapps/slots_dashboard/alert_mail.txt": error=2, No such file or directory</p>
  
  <p>if i change the command to whoami i get tomcat in the response, i even went to the servers computer and tried the command from there and there was no problem. guys, please help :(</p>