Here's what I'm looking at, a python script uses subprocess.run (or call, or popen, it doesn't seem to matter) to run a simple windows batch script, the batch file returns a non-zero exit code, but python thinks the return code was zero.
Here's the simple repro I have right now:
Batch script (error.bat):
@echo off
if "%1" == "a" (
exit /b 1
goto end
)
:end
Python script:
import subprocess
retcode = subprocess.run(['error.bat', 'a'])
print(retcode)
Running the batch file from the command line results in %errorlevel% being set to 1. But running the python script the return code comes back as 0:
CompletedProcess(args=['error.bat', 'a'], returncode=0)
For a simpler script this works fine, but somehow something about the if statement and the goto results in python losing the return code. Is there something I'm missing here? Is this a python bug (I'm using 3.6)?