我以前使用过pexpect
and sendline
,但这次我使用管道和通配符运行更长的命令,见下文:
commandToRun='/bin/bash -c "/var/scripts/testscripts//extract -o | tail -3"'
returnedString = sendLine(commandToRun)
我的具有 sendLine 函数的类看起来很像这样:
self.connection = pexpect.spawn('%s %s' % (protocol, host))
self.connection.setecho(False)
self.connection.setwinsize(300, 300)
但是当我运行代码时,我看到它returnedString
不仅包括响应,还包括请求。
所以如果我打印returnedString
,它看起来像这样:
bin/bash -c "/var/scripts/testscripts//extract -o | tail -3"<cr>
100<cr>
102<cr>
103<cr>
为什么响应将请求包含在同一个缓冲区中?
我已经设置setecho(False)
了,它没有帮助!
编辑:(正确修复)我必须手动从响应中删除所有内容并删除请求。所以 setecho(False) 仍然什么都不做!