supplying password to subprocess.call('rsync ...'), os.system('rsync ...')

Stargaming stargaming at gmail.com
Fri Oct 5 18:23:50 CEST 2007


On Fri, 05 Oct 2007 08:37:05 -0700, timw.google wrote:

> On Oct 5, 10:33 am, "timw.google" <tjand... at yahoo.com> wrote:
>> Hi
>>
>> I want to write a python script that runs rsync on a given directory
>> and host. I build the command line string, but when I try to run
>> subprocess.call(cmd), or p=subprocess.Popen(cmd, shell=True),or
>> os.system(cmd), I get prompted for my login password. I expected this,
>> but when I try to give my password, it's echoed back to the terminal
>> and the special characters in the password is (I think) getting
>> interpreted by the shell (zsh)
>>
>> I can't ssh w/o supplying a password. That's the way the security is
>> set up here.
>>
>> How do I use python to do this, or do I just have to write a zsh
>> script?
>>
>> Thanks.
> 
> I wrote a zsh script to do what I wanted, but I'd still like to know how
> to do it in Python.

`subprocess.Popen` has a keyword argument called `stdin` -- what takes 
the password, I guess. Assigning `subprocess.PIPE` to it and using 
`Popen.communicate` should do the trick. 

Check the documentation at http://docs.python.org/lib/module-
subprocess.html for details.

Cheers,
Stargaming



More information about the Python-list mailing list