문제

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 :(

도움이 되었습니까?

해결책

You want the read() method:

p = pexpect.spawn('ssh  %s@%s ls'%(un,ip), timeout)
print(p.read())
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top