subprocess pipe

Camille Harang mammique at
Sun Nov 14 19:50:54 CET 2010

Hi all,

I'm having a problem with subprocess.Popen. It seems that its unable to
capture the pg_dump's standard inputs & outputs in a non-shell mode:

from subprocess import Popen, PIPE

# fire pg_dump in order to read data from the file object pgsql.stdout
pgsql = Popen(['/usr/bin/pg_dump',
               '--host', 'localhost',

# pg_dump prompts for password so I inject it in stdin.
pgsql.stdin.write('MY_PASSWORD' + '\n')

In the shell mode (shell=True) pipes works but the args (username, etc.)
are omitted. If I turn to shell=False the arguments are passed to
pg_dump but subprocess.Popen is no longer able to capture the standard
inputs & outputs, the password prompt appears on the TTY instead and
doesn't take the input written in stdin. It seems that subprocess.Popen
has only this problem with pg_dump, other interactive command lines
seems to be correctly handled.

Any lead?



More information about the Python-list mailing list