Python's Subprocess.Popen With Shell=True. Wait till it is completed
--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Riding Sky Waves v001
--
Chapters
00:00 Python'S Subprocess.Popen With Shell=True. Wait Till It Is Completed
01:26 Answer 1 Score 1
01:39 Accepted Answer Score 2
02:13 Answer 3 Score 1
02:31 Thank you
--
Full question
https://stackoverflow.com/questions/2045...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #subprocess #popen
#avk47
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Riding Sky Waves v001
--
Chapters
00:00 Python'S Subprocess.Popen With Shell=True. Wait Till It Is Completed
01:26 Answer 1 Score 1
01:39 Accepted Answer Score 2
02:13 Answer 3 Score 1
02:31 Thank you
--
Full question
https://stackoverflow.com/questions/2045...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #subprocess #popen
#avk47
ACCEPTED ANSWER
Score 2
As @mikkas suggest just use it as a list here is a working example:
mainProcess = subprocess.Popen(['python', pyfile, param1, param2], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# get the return value from the method
communicateRes = mainProcess.communicate()
stdOutValue, stdErrValue = communicateRes
You are calling python.exe pyfile param1 param2
By using communicate() you can get the stdout and stderr as a Tuple
You can use python method split() to split your string to a list for example:
cmd = "python.exe myfile.py arg1 arg2"
cmd.split(" ")
Output:
['python.exe', 'myfile.py', 'arg1', 'arg2']
ANSWER 2
Score 1
I think the check_call function should wait for the command to finish.
See the docs here http://docs.python.org/2/library/subprocess.html
ANSWER 3
Score 1
Check call does not wait. You need to do a process.wait() and check the return code explicitly to get the functionaly you want.
Process = subprocess.Popen('%s' %command_string,stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
Process.wait()
if Process1.returncode!=0:
print Process1.returncode
sendMail()
return
else:
sendMail()