title: Run linux command in java to send email with quotes
body: <p>I am able to send emails in Linux via commandline:</p>
  
  <pre><code>cat &lt; x.txt | mail -s "SUBJECT" email@email.com
  </code></pre>
  
  <p>This works perfectly. Note: The body is in <code>x.txt</code>. </p>
  
  <p>Now, I want to execute exactly this command with Java.</p>
  
  <pre><code>Process p = Runtime.getRuntime().exec(
              new String[] { "cat &lt; x.txt", "|", "mail -s", "SUBJECT",
                      "email@email.com" });
  
      p.waitFor();
      BufferedReader buf = new BufferedReader(new InputStreamReader(
              p.getInputStream()));
      String line = "";
      String output = "";
  
      while ((line = buf.readLine()) != null) {
          output += line + "\n";
      }
  
  System.out.println(output);
  </code></pre>
  
  <p>Well, It is not working and I am getting following error. </p>
  
  <pre><code>Exception in thread "main" java.io.IOException: Cannot run program "cat &lt; x.txt |": error=2, Datei oder Verzeichnis nicht gefunden
          at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
          at java.lang.Runtime.exec(Runtime.java:620)
          at java.lang.Runtime.exec(Runtime.java:485)
          at test.main(test.java:9) Caused by: java.io.IOException: error=2, Datei oder Verzeichnis nicht gefunden
          at java.lang.UNIXProcess.forkAndExec(Native Method)
          at java.lang.UNIXProcess.&lt;init&gt;(UNIXProcess.java:248)
          at java.lang.ProcessImpl.start(ProcessImpl.java:134)
          at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
          ... 3 more
  </code></pre>
  
  <p>Am I splitting those command(s) wrong?</p>
  
  <p>How can I execute this command properly?</p>