Python how to read output from pexpect child?

后端 未结 6 1795
攒了一身酷
攒了一身酷 2020-12-29 22:51
child = pexpect.spawn (\'/bin/bash\')
child.sendline(\'ls\')
print(child.readline())
print child.before, child.after

All I get with this code in my

6条回答
  •  一向
    一向 (楼主)
    2020-12-29 23:04

    Try the following:

    import pexpect
    child = pexpect.spawn('ls')
    print child.read() # not readline
    

    The read() will give you the entire output of the ls.

提交回复
热议问题