pexpect.exitstatus not working?
Laszlo Zsolt Nagy
gandalf at geochemsource.com
Thu Sep 1 05:34:55 EDT 2005
This function:
def scp(from_path,to_path,pwd):
"""Copy a file with scp."""
cmd = '/bin/csh -c "scp -q %s %s ; echo XXX"' %(from_path,to_path)
print cmd
child = pexpect.spawn(cmd)
child.expect('Password:')
child.sendline(pwd)
child.expect('XXX')
return child.exitstatus
always returns None. This one:
def scp(from_path,to_path,pwd):
"""Copy a file with scp."""
cmd = 'scp -q %s %s ' %(from_path,to_path)
print cmd
child = pexpect.spawn(cmd)
child.expect('Password:')
child.sendline(pwd)
child.interact()
return child.exitstatus
will return the correct exit status. The big problem is that I would
like to run this function from a cron job. Inside a cron job, interact()
will not work because it is not connected to a real terminal. How can I
get the exit status code? Please help me.
Les
More information about the Python-list
mailing list