title: Runtime.exec() can't run "su - postgres -c 'pg_dump ...'"
body: <p>This is the command I want to run:</p>
  
  <pre><code>su - postgres -c "pg_dump ....."
  </code></pre>
  
  <p>to backup the postgres database.</p>
  
  <p>If I am now in linux shell, as a root, it works great.</p>
  
  <p>But now, I want to run it from a java application, as:</p>
  
  <pre><code>String cmd = "su - postgres -c \"pg_dump --port 5432 .....\""
  Process p = Runtime.getRuntime().exec(cmd);
  // read the error stream and input stream
  p.waitFor();
  </code></pre>
  
  <p>It throws an error:</p>
  
  <pre><code>su: unknown option "--port"
  please try "su --help" to get more information
  </code></pre>
  
  <p>Now I change the code as:</p>
  
  <pre><code>Process p = Runtime.getRuntime().exec(new String[0]{cmd});
  // read the error stream and input stream
  p.waitFor();
  
  Cannot run program "su - postgres -c \"pg_dump .....\"": java.io.IOException: error=2, no that file or directory
  </code></pre>
  
  <p>What should I do now?</p>