pexpect exceptions
Manuel de Ferran
mgoogle at deferran.com
Wed Jan 28 04:21:49 EST 2004
Michael Surette <msurette at laframboise.net> wrote in message news:<pan.2004.01.26.22.07.43.147063 at laframboise.net>...
> I have been trying to automate the changing of passwords using python and
> pexpect. I wrote a script as a test and it works, except that it gives me
> an exception when it stops running:
>
> Exception exceptions.OSError:
> (10, 'No child processes') in <bound method spawn.__del__ of
> <pexpect.spawn instance at 0x403d938c>> ignored
>
> What is happening and how do I get rid of the exception?
>
> I am running python 2.3.2 under Slackware linux 9.1 and pexpect 0.99.
> Here is the script:
>
> #!/usr/bin/python
> import pexpect
> import sys
>
> if len(sys.argv) != 3:
> print 'usage error!'
> raise SystemExit
>
> name= sys.argv[1]
> passwd= sys.argv[2]
>
> a= pexpect.spawn('passwd %s'%name)
>
> changed= False
> while not changed:
> i= a.expect(['[Nn]ew password:','[Cc]hanged'])
> if i == 0:
> a.sendline(passwd)
> elif i == 1:
> changed= True
I have the same issue with the following code :
#!/usr/bin/env python
'''This runs "ls -l" on a remote host using SSH.
At the prompts enter hostname, user, and password.
'''
import pexpect
import getpass
host = raw_input('Hostname: ')
user = raw_input('User: ')
password = getpass.getpass('Password: ')
child = pexpect.spawn("ssh -l %s %s /bin/ls -l"%(user, host))
child.expect('password:')
child.sendline(password)
child.expect(pexpect.EOF)
print child.pid,'middle',child.isalive()
print child.before
This is a slighty modified version of sshls.py (shipped with
pexpect-examples). I've only added "print
child.pid,'middle',child.isalive()"
and I get the same exception : "exceptions.OSError: (10, 'No child
processes')"
The weird thing I can't explain is that, I don't get the exception
without ",child.alive()"
More information about the Python-list
mailing list