我正在调用子进程(期望脚本运行一些命令),并且需要等待直到它完成启动另一个函数,但是我认为它只等待直到shell命令完成,而不是期望脚本。可以等整个流程完成吗?
p111 = subprocess.Popen('gnome-terminal -e "perl /tmp/expect',shell=True)
os.waitpid(p111.pid,0)
smo_final()
使用
https://docs.python.org/2/library/subprocess.html subprocess.Popen.wait
p11 = subprocess.Popen('gnome-terminal -e "perl /tmp/expect',shell=False)
p11.wait()
使用python期望实现pexpect
import pexpect
...
child = pexpect.spawn(cmd) # the command you want to run
child.expect(str_expect) # the string you expect
child.sendline(str_response) # the string with which you'd like to respond
child.wait() # wait for the child to exit
...
# the rest of your code here