473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

pexpect exceptions

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
Jul 18 '05 #1
2 5327
Michael Surette <ms******@laframboise.net> wrote in message news:<pa****************************@laframboise.n et>...
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()"
Jul 18 '05 #2
On Wed, 28 Jan 2004 01:21:49 -0800, Manuel de Ferran wrote:
Michael Surette <ms******@laframboise.net> wrote in message news:<pa****************************@laframboise.n et>...
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()"


I have found a solution and an explanation.

Adding "a.close(False)" as a last line of my script fixes the problem.
The spawn.close() function calls os.pidwait() with your child process pid.
In our two cases, that pid is dead and os.pidwait rightfully raises an
exception. Calling spawn.close() with a False argument bypasses this
call.

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Adrian Casey | last post by:
I have a collection of tcl expect scripts which I am converting to python using the excellent pexpect module (http://pexpect.sourceforge.net/). So far I've had great success in getting all my...
0
by: edwin | last post by:
Hi, I'm using pexpect in a plugin script within bartbot (an python based irc bot). When I execute the plugin, python comes back with: ERROR exceptions.ValueError file:...
5
by: funkyj | last post by:
I love pexpect because it means I may never have to use expect again (I don't do any heavy expect lifting -- I just need simple tty control)! As a python advocate I find it embarassing how...
0
by: dwelch91 | last post by:
I'm having a problem using pexpect with 'sudo' on Ubuntu 6.06 (Dapper). Here's the program: #!/usr/bin/env python import pexpect import sys child = pexpect.spawn("sudo apt-get update")...
5
by: half.italian | last post by:
Hi all. I try not to post until I am stuck in hole with no way out. I fought with this for several hours, and am currently in the hole. I'm doing a proof of concept for creating afp shares...
1
by: Kevin Erickson | last post by:
Hello, I am attempting to use pexpect in python to copy files from a server using scp; the copy works however exceptions are thrown and it exits unsuccessfully. Below is the a sample code and...
8
by: asgarde | last post by:
hello, I'm new in Python and i would like to use Pexpect to execute a root command (i want to mount via a Pyhton script a drive) so that's my script for the moment : from os import *...
5
by: crybaby | last post by:
I need to ssh into a remote machine and check if mytest.log file is there. I have setup ssh keys to handle login authentications. How do I determine if mytest.log is there by using Pexpect. What...
2
by: yellowblueyellow | last post by:
Hey , I need to SSH into a server .. (10.8.42.38) using pexpect the username is 'admin' and password is 'abc123' so far i have the following code import pexpect import sys import time...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.