I am pretty confused right now.

pexpect documentation states the following:

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)

However I am looking at some old code that uses | and * in pexpect.sendline(some command | grep 'something'). So I started to test these command and they all seem to work. It is also worth mentioning that I am not using a modified pexpect module, it is plain old pexpect for python.

How come? why does pexpect mention that meta characters does not work, when it obviously does so?

有帮助吗?

解决方案

pexpect.spawn doesn't interpret shell meta characters, but whatever's running inside pexpect (presumably a shell) clearly does:

child = pexpect.spawn('/bin/bash')
child.sendline('echo hello | cat')

pexpect is just passing the string to the child process; it's not interpreting it.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top