i have some sort of processes :
subprocess.Popen(['python2.7 script1.py')],shell=True)
subprocess.Popen(['python2.7 script2.py')],shell=True)
subprocess.Popen(['python2.7 script3.py')],shell=True)
subprocess.Popen(['python2.7 script4.py')],shell=True)
i want to each one starts after the previous process completely finish. i mean
subprocess.Popen(['python2.7 script2.py')],shell=True)
starts after
subprocess.Popen(['python2.7 script1.py')],shell=True)
completly finished, and for others the same. this is cause previous scripts has output that it is used by next script. thanks
2 Answers 2
Use subprocess.call:
Run the command described by args. Wait for command to complete, then return the
returncodeattribute.
In your example:
subprocess.call(['python2.7 script1.py'],shell=True)
subprocess.call(['python2.7 script2.py'],shell=True)
subprocess.call(['python2.7 script3.py'],shell=True)
subprocess.call(['python2.7 script4.py'],shell=True)
Tiago Peres
15.9k22 gold badges105 silver badges174 bronze badges
answered Jul 17, 2017 at 7:30
Christian König
3,57020 silver badges29 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
You can simply use wait() for each one to finish, like this :
sp1 = subprocess.Popen(['python2.7 script1.py'],shell=True)
sp1.wait()
sp2 = subprocess.Popen(['python2.7 script2.py'],shell=True)
sp2.wait()
sp3 = subprocess.Popen(['python2.7 script3.py'],shell=True)
sp3.wait()
sp4 = subprocess.Popen(['python2.7 script4.py'],shell=True)
sp4.wait()
Or in shorter way :
subprocess.Popen(['python2.7 script1.py'],shell=True).wait()
subprocess.Popen(['python2.7 script2.py'],shell=True).wait()
subprocess.Popen(['python2.7 script3.py'],shell=True).wait()
subprocess.Popen(['python2.7 script4.py'],shell=True).wait()
london_utku
1,3122 gold badges20 silver badges47 bronze badges
answered Jul 17, 2017 at 7:28
Qrom
4971 gold badge5 silver badges21 bronze badges
1 Comment
london_utku
There is a paranthesis mistake here : (['python2.7 script1.py')], which should be corrected.
Explore related questions
See similar questions with these tags.
lang-py