title: How to parse psql output with subprocess.Popen
body: <p>I want to execute the command <code>psql --username=fred myDB &lt; //10.0.0.1/share/dump.sql.pgdump</code> but through <code>subprocess.Popen</code>, so that I can parse the output. However, I get the following error when doing so:</p>
  
  <pre><code>&gt;&gt;&gt; psql: warning: extra command-line argument "&lt;" ignored
  &gt;&gt;&gt; psql: warning: extra command-line argument "//10.0.0.1/share/dump.sql.pgdump" ignored
  </code></pre>
  
  <p>It seems I'm not formatting the command correctly, but I don't understand why. This is what I have so far:</p>
  
  <pre><code>PASS = 'mypassword'
  os.putenv('PGPASSWORD', PASS)
  latest_dump = '//10.0.0.1/share/dump.sql.pgdump'
  cmd = ['psql', '--username=fred', 'myDB', '&lt;', latest_dump]
  p = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
  
  # Print each line
  for line in iter(p.stdout.readline, b''):
      sys.stdout.flush()
      print("&gt;&gt;&gt; " + line.rstrip())
  </code></pre>