I'm trying to create a python script that starts a new window and waits for it to complete, and then retrieve the exit code. So I am using Popen with start /wait
to create a separate window for it, but this does not properly forward the exit code.
This code summarizes the problem:
import subprocess
params = {}
params['stdout'] = subprocess.PIPE
params['stderr'] = subprocess.PIPE
params['shell'] = True
proc = subprocess.Popen('start /wait cmd /c exit 1', **params)
# This works but the above line does not
#proc = subprocess.Popen('exit 1', **params)
resultCode = proc.wait()
print(resultCode)
The documentation for start /wait
suggests that it should return the exit code, and when I run it manually and then check %ERRORLEVEL%
it appears correct, so I'm not sure what I'm doing wrong