The title looks like fishing, but I don't have time to elaborate, so please forgive me. For example, suppose you have this Python code.
hoge.py
# encoding: utf-8
import sys
if __name__=='__main__':
if somehow:
hoge1()
sys.exit(0)
else:
sys.exit(1)
After calling this from the batch file, you can get the value of% ERRORLEVEL% sys.exit ().
hoge.bat
@echo off
python3 hoge.py
IF %ERRORLEVEL%==0 foo.bat
Now you can do something like running foo.bat if the value of sys.exit () is 0, otherwise doing nothing.
However, I saw somewhere that the role of% ERRORLEVEL% is decided by the system up to about 128, so I may not be able to do it. This is the result of struggling to get the result of Python script because I wanted to do some processing, but the corresponding code will be described later.
Recommended Posts