How can I send single ssh command to get result string with pexpect?
问题 I am trying to make my code as efficient and simple as possible. I would like to make my pexpect command into 1 line: Current command (simplified): import pexpect ... session=pexpect.spawn( 'ssh %s@%s'%(un,ip), timeout) session.expect(prompt, timeout) session.sendline('ls') session.expect(prompt) print session.before I would like to do this all in my ssh command but I am returning a pexpect object, is there a way to return just the output string? import pexpect ... print str(pexpect.spawn(