popen and password entry

Sinan Nalkaya orome.the.valar at gmail.com
Thu Jun 15 08:58:48 CEST 2006


hi,
i have found expect method for this purpose. i`m trying to use pexpect but
following code gives me an something strange as a result.
# The CODE
import pexpect
cmd = '/usr/bin/rsync config root at 10.1.1.2:/tmp/.'
#cmd = 'ssh root at 10.1.1.2'
child = pexpect.spawn(cmd)
passwd = 'qwe123'
try:
        i = child.expect(['Password:','Password: ',pexpect.EOF,
pexpect.TIMEOUT])
        if i == 0:      child.sendline(passwd)
        elif i == 1:    print 1
        elif i == 2:    print 2
        elif i == 3:    print 3
except EOF:     print 'EOF'
except TIMEOUT: print 'TIMEOUT'
print 'finished'

# The result
finished
Exception pexpect.ExceptionPexpect: <pexpect.ExceptionPexpect instance at
0xb7dfab2c> in <bound method spawn.__del__ of <pexpect.spawn instance at
0xb7db3a2c>> ignored
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060615/238495e4/attachment.html>


More information about the Python-list mailing list