pexpect.exitstatus not working?

  • Thread starter Laszlo Zsolt Nagy
  • Start date
L

Laszlo Zsolt Nagy

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top