Laszlo Zsolt Nagy wrote: >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. > .... >How can I >get the exit status code? Please help me. > > I could develop a workaround, but this is a real hack, using bourne shell and the $? variable. def scp(from_path,to_path,pwd): """Copy a file with scp. Return the exit code.""" cmd = '/bin/sh -c "scp -q %s %s ; echo $? ; echo XXX "' %(from_path,to_path) print cmd child = pexpect.spawn(cmd) child.expect('Password:') child.sendline(pwd) child.expect("XXX") parts = [] for item in child.before.split('\n'): if item.strip() != "": parts.append(item.strip()) code = int(parts[-1]) print "exit code:", code if (code != 0): print parts[0] return code Is there a platform independent solution? Les
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4