subprocess pipe

Nobody nobody at nowhere.com
Mon Nov 15 09:08:26 CET 2010


On Sun, 14 Nov 2010 19:47:55 +0000, Tim Harig wrote:

> On 2010-11-14, Camille Harang <mammique at garbure.org> wrote:
>> # pg_dump prompts for password so I inject it in stdin.
>> pgsql.stdin.write('MY_PASSWORD' + '\n')
> 
> For security reasons, some programs use direct access to the TTY system
> for password entry rather then reading from stdin.

Indeed, the getpass() function exists[1] for this purpose:

       The  getpass() function opens /dev/tty (the controlling terminal of the
       process), outputs the string prompt, turns off echoing, reads one  line
       (the  "password"),  restores  the  terminal  state  and closes /dev/tty
       again.

[1] Or existed. It was dropped from the Unix standard in POSIX.1-2001, but
most systems still provide it.



More information about the Python-list mailing list