Search code examples
pythoncmd

Checking if a .cmd file was executed successfully with python


I wrote a script that executes certain .cmd files. I'm trying to find a way to check if the execution finished with errors or not. This is how the final line of the .cmd file looks like, it shows you the number of warnings and errors:

https://i.sstatic.net/y6K1m.png (sorry i do not have enough rep to make the image embedded between the text :()

I tried saving the console output to a variable, and then check if the substring "Error(s)" was inside the text, but that didn't seem to work... I'm fairly new to python and I'm running out of ideas and to stuff to try, any suggestions would be appreciated. Let me know if you need more details. Thanks in advance guys!


Solution

  • Batch scripts usually have a return code that you can check if it completed successfully.

    Check this link for the exit codes

    And check this question for the python code to get them