簡體   English   中英

子進程等待腳本完成

[英]Subprocess wait expect script to finish

我正在調用子進程(期望腳本可以運行一些命令),並且需要等到它完成以啟動另一個功能,但是與此同時,我認為它只等到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()

使用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