title: Python - subprocess.check_call gives a CalledProcessError exception
body: <p>I want to call a subprocess to backup mysql database.
  A command line which ran fine in the terminal (and created a file named mydatabase.sql) is:</p>
  
  <pre><code>    mysqldump -uroot -ppassword --add-drop-database --database mydatabase &gt; mydatabase.sql
  </code></pre>
  
  <p>Now the code to be ran by python to call a subprocess:</p>
  
  <pre><code>    args = shlex.split('mysqldump -uroot -ppassword --add-drop-database --database mydatabase &gt; mydatabase.sql')
      subprocess.check_call(args)
  </code></pre>
  
  <p>The exeption is raised (no file created):</p>
  
  <pre><code>    Traceback (most recent call last):
        File "&lt;pyshell#29&gt;", line 1, in &lt;module&gt;
          subprocess.check_call(args)
        File "/usr/lib/python3.2/subprocess.py", line 485, in check_call
          raise CalledProcessError(retcode, cmd)
      subprocess.CalledProcessError: Command '['mysqldump', &gt;'-uroot', '-ppassword', '--add-drop-database', '--database', &gt;'mydatabase', '&gt;', 'mydatabase.sql']' returned non-zero exit status 2
  </code></pre>
  
  <p>I have tried different ways, but they still don't work:</p>
  
  <pre><code>    args = shlex.split('/opt/lampp/bin/mysqldump -uroot -ppassword --add-drop-database --database mydatabase &gt; mydatabase.sql')
      subprocess.check_call(args)
  </code></pre>
  
  <p>or </p>
  
  <pre><code>    args = shlex.split('/opt/lampp/bin/mysqldump -uroot -ppassword --add-drop-database --database mydatabase &gt; mydatabase.sql')
      subprocess.Popen(args)
  </code></pre>
  
  <p>I also tried with shell=True or or shell=False. In both cases, they still don't work.</p>
  
  <p>I have read the docs, google for the answer for my problem, but I haven't got a clue how to show my problem. stackoverflow is probably my last hope.</p>