【发布时间】:2012-11-22 00:19:33
【问题描述】:
我现在很困惑。
pexpect documentation 声明如下:
Remember that Pexpect does NOT interpret shell meta characters such as
redirect, pipe, or wild cards (>, |, or *). This is a common mistake.
If you want to run a command and pipe it through another command then
you must also start a shell. For example::
child = pexpect.spawn('/bin/bash -c "ls -l | grep LOG > log_list.txt"')
child.expect(pexpect.EOF)
但是,我正在查看一些在 pexpect.sendline(some command | grep 'something') 中使用 | 和 * 的旧代码。
所以我开始测试这些命令,它们似乎都可以工作。还值得一提的是,我没有使用修改过的 pexpect 模块,它是 python 的普通 pexpect。
怎么会?为什么 pexpect 提到 元字符不起作用,而它显然是这样做的?
【问题讨论】:
-
代码传递给
pexpect.sendline()的是什么? -
@ecatmur,特定于机器的命令,但通常带有 |命令后的 grep 或 |和 *。见上面修改过的代码。
标签: python ssh pexpect metacharacters