简体   繁体   English

子进程等待脚本完成

[英]Subprocess wait expect script to finish

I'm calling the subprocess (expect script to run some command) and need to wait until it is finished to start another function, but with this I think it only wait until shell command is finihed, and not the expect script. 我正在调用子进程(期望脚本可以运行一些命令),并且需要等到它完成以启动另一个功能,但是与此同时,我认为它只等到shell命令完成后才开始,而不是期望脚本。 Is it possible to wait for the whole process to finish? 是否可以等待整个过程完成?

 p111 = subprocess.Popen('gnome-terminal -e "perl /tmp/expect',shell=True)  
    os.waitpid(p111.pid,0)
    smo_final()

Use 采用

https://docs.python.org/2/library/subprocess.html#subprocess.Popen.wait https://docs.python.org/2/library/subprocess.html#subprocess.Popen.wait

  p11 = subprocess.Popen('gnome-terminal -e "perl /tmp/expect',shell=False)  
  p11.wait()

Use pexpect, a python expect implementation 使用pexpect,python期望实现

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM