0

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( 'ssh  %s@%s ls'%(un,ip), timeout))

Is there a possible way to change the code above to work?

I have to use pexpect or standard python 2.4, not paramiko :(

1 Answer 1

1

You want the read() method:

p = pexpect.spawn('ssh  %s@%s ls'%(un,ip), timeout)
print(p.read())
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.