child = pexpect.spawn ('/bin/bash')
child.sendline('ls')
print(child.readline())
print child.before, child.after
我输出的这些代码
ls
ls
但当我的密码是
child = pexpect.spawn('ls')
print(child.readline())
print child.before, child.after
然后就可以了,但只对前两张照片有效。我用错发送命令了吗?我试着发,写,发,再也找不到了。
Tags:
打开日志文件:- 前往终点站
在pexpect中,
before
和after
属性在expect
方法之后填充。在这种情况下,最常用的方法是等待提示(这样您就知道前面的命令已经完成执行)。所以,在你的例子中,代码可能看起来像这样:请尝试以下操作:
read()
将为您提供ls的整个输出。相关问题 更多 >
编程相关推荐