Shell pexpect响应包括带有<;cr>;

Shell pexpect响应包括带有<;cr>;,shell,python-2.7,pexpect,Shell,Python 2.7,Pexpect,我以前使用过pexpect和sendline,但这次我使用管道和通配符运行了更长的命令,请参见以下内容: commandToRun='/bin/bash -c "/var/scripts/testscripts//extract -o | tail -3"' returnedString = sendLine(commandToRun) 我的类具有sendLine函数,看起来非常像: self.connection = pexpect.spawn('%s %s' % (protocol

我以前使用过
pexpect
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)
bin/bash -c "/var/scripts/testscripts//extract -o | tail -3"<cr>
100<cr>
102<cr>
103<cr>
但是当我运行代码时,我看到
returnedString
不仅包括响应,还包括请求

因此,如果我打印
returnedString
,它看起来像这样:

    self.connection = pexpect.spawn('%s %s' % (protocol, host))
    self.connection.setecho(False)
    self.connection.setwinsize(300, 300)
bin/bash -c "/var/scripts/testscripts//extract -o | tail -3"<cr>
100<cr>
102<cr>
103<cr>
bin/bash-c”/var/scripts/testscripts//extract-o | tail-3”
100
102
103
为什么响应将请求包含在同一缓冲区中? 我已经设置了
setecho(False)
,但它没有帮助


编辑:(更正)我必须手动删除响应中的所有内容,并删除请求。所以setecho(False)仍然什么都不做

我自己找到了解决办法。(响应时关闭回声)


基本上,在shell中使用“
bash-c
”运行命令,然后在bash中打开
echo

什么是
sendLine()
?sendline()方法返回字节数written@J.F.Sebastian,我编辑了上面的代码!您能否提供一个最小的(只执行一个命令)完整的(可以独立运行)示例来重现您的问题。@J.F.Sebastian,这将很难,因为我在无法共享的机器上运行该命令。问题很简单?为什么请求在响应中得到响应?为什么它在回声中包含载波返回字符?嘿,我和你面临着同样的问题。。。。找到答案了吗?