0
我正在尝试使用pexpect自动交互式python脚本。但是在控制权回归到关注点之后,它不会继续。与pexpect中的python脚本交互
这是一个模拟脚本尝试模拟相同的事情。
---------------- python script(script.py) -----------------
def issue_command():
print "********** in issue_command ********"
def dummy_check():
print "********** in dummy_check ********"
raw_input("Now Press enter for next command")
issue_command()
if __name__ == "__main__":
dummy_check()
--------------------------------Pexpect script(pexp.py)-----------------------
import pexpect
import sys
def quick_test():
pobj = pexpect.spawn("/bin/bash")
pobj.logfile = sys.stdout
pobj.sendline("script.py")
pobj.expect("Now Press enter for next command")
print "\n1st part is done. Now execute the oil command"
pobj.sendline()
if __name__ == "__main__":
quick_test()
-------------------------------------------------------------------
我期望输出如下。
$python pexp.py
********** in dummy_check ********
Now Press enter for next command -------------------> It should wait here. Upon pressing enter it should print the next line.
********** in issue_command ********
$
相反,它不打印二号线即Pexpect的不能用脚本交互 它之间在返回后。
$ python pexp.py
./script.py
********** in dummy_check ********
Now Press enter for next command -----> It ignored sendline() and did not execute issue_command function.
$
我也试图通过直接在pexpect.spawn脚本(script.py)(),而不是创建另一个shell程序(/ bin/bash)的。它没有帮助。 我不知道我在做什么错。有人可以请指教吗?
谢谢。