我正在浏览 pexpect 文档,它说您可以调用 run() 函数来执行命令并返回输出
所以我做了以下但它出错了。我在这里错过了什么吗?
>>> pexpect.run('pwd')
'/home/vijay\r\n'
>>> pexpect.run('cd /home')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/pexpect.py", line 219, in run
child = spawn(command, maxread=2000, logfile=logfile, cwd=cwd, env=env)
File "/usr/lib/python2.7/dist-packages/pexpect.py", line 429, in __init__
self._spawn (command, args)
File "/usr/lib/python2.7/dist-packages/pexpect.py", line 516, in _spawn
raise ExceptionPexpect ('The command was not found or was not executable: %s.' % self.command)
pexpect.ExceptionPexpect: The command was not found or was not executable: cd.
>>>
我正在编写一个脚本,在该脚本上我下载了一个 git 存储库并想要执行 cd (到该存储库),然后传递一些命令。所以我决定使用 pexpect 模块,因为它提供了交互式控制台
让我知道我是否在这里遗漏了什么?
谢谢,-维杰