user3319356
user3319356

Reputation: 173

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. 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()

Upvotes: 0

Views: 3211

Answers (2)

e271p314
e271p314

Reputation: 4039

Use pexpect, a python expect implementation

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

Upvotes: 0

Hitesh Dharamdasani
Hitesh Dharamdasani

Reputation: 862

Use

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

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

Upvotes: 1

Related Questions