Hi all,
I have the following code that uses pexpect to execute a system command. My
problem is, I don't know how to identify if the command was successfully
executed.
The code works as it is to execute the SCP command, but it executes
regardless if the SCP session can actually connect to something.
Thanks
def doScp(files):
logger.log("Files to get: " + `files`)
fNames = ' '.join(files)
cmd = 'scp %s %s@%s:%s%s' % (fNames,
SCP_USERNAME,
SCP_HOST,
SCP_IMG_FILE_DIR,
SCP_IMG_FILE_PATH)
logger.log("Sending: " + cmd)
child = pexpect.spawn(cmd)
i = child.expect(['assword:', 'yes/no'], timeout=30)
if i == 0:
child.sendline(SCP_PASSWD)
elif i == 1:
child.sendline("yes")
child.expect("assword:", timeout=30)
child.sendline(SCP_PASSWD)
data = child.read()
if data != None:
success = True
else:
success = False
child.close()
logger.log("Files sent to SCP host")
return success
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor