I am trying to get the exit code from a Batch file. To be more specific I am having issues to get the ERRORLEVEL.
I tried using Popen, check_output,call, check_call:
out = os.system(BatchFilePath)
out, err = subprocess.Popen(BatchFilePath,stderr=subprocess.PIPE, shell=True).communicate()
out,err = subprocess.Popen(BatchFilePath, stderr=subprocess.PIPE).communicate()
out = subprocess.Popen(BatchFilePath, shell=True).stderr
out = os.system(BatchFilePath)
out = subprocess.check_call(BatchFilePath)
out = subprocess.call(BatchFilePath, shell=True)
out = subprocess.check_output(buildPath, shell=True)
Which most of the times return empty or 0
I also tried using
SET ERRORLEVEL=1
exit /B !ERRORLEVEL!
but without luck. I also tried
set RC=
setlocal
somecommand.exe
endlocal & set RC=%ERRORLEVEL%
exit /B %RC%
Anotherway to do it is to
out, err = subprocess.Popen(BatchFilePath,stdout=subrocess.PIPE,stderr=subprocess.PIPE, shell=True).communicate()
and searching for the string "ERROR" or "FAILURE" from the out variable.
On the other hand by doing so the user will not see all the echos from the batch file thus the screen will be empty without any messages until the batch file finish and print the appropriate message from my python script.
So I dont need to use the stdout=subrocess.PIPE option from the Popen because its printing all the echos from the batch.
I am working with the CMD and not the powershell. and I am using python 2.7
I searched in the google and here and I wasnt able to find anything that will help me. Any help will be appreciate.