Get the return code of the Python script from bat

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

Get the return code of the Python script from bat
[Python] Get the character code of the file
Get the contents of git diff from python
Get the return value of an external shell script (ls) with python3
[Python] Get the text of the law from the e-GOV Law API
Existence from the viewpoint of Python
Get the address from the zip code
Learning notes from the beginning of Python 1
[Python3] Rewrite the code object of the function
[Python] Get the update date of a news article from HTML
Get the EDINET code list in Python
Learning notes from the beginning of Python 2
[Python] Get the main color from the screenshot
I tried to get the authentication code of Qiita API with Python.
[Python] Get the main topics of Yahoo News
[Python] Read the source code of Bottle Part 1
[Python] Get the last updated date of the website
Code for checking the operation of Python Matplotlib
Convert the character code of the file with Python3
[Python] Get the day of the week (English & Japanese)
Get the update date of the Python memo file.
the zen of Python
Get only the source code of the PyPI package with pip from the command line
Python script to get a list of input examples for the AtCoder contest
The wall of changing the Django service from Python 2.7 to Python 3
Template of python script to read the contents of the file
How to get the number of digits in Python
Learn Nim with Python (from the beginning of the year).
[Python] Get the official file path of the shortcut file (.lnk)
Get the absolute path of the script you are running
[python] Get the list of classes defined in the module
Study from the beginning of Python Hour1: Hello World
Python points from the perspective of a C programmer
Get the size (number of elements) of UnionFind in Python
[Python] Get the list of ExifTags names of Pillow library
[Maya Python] Crush the contents of the script 2 ~ list Notes
Study from the beginning of Python Hour8: Using packages
Get the operation status of JR West with Python
Script to get the expiration date of the SSL certificate
[Python] Get the number of views of all posted articles
Get the URL of the HTTP redirect destination in Python
A python script that gets the number of jobs for a specified condition from indeed.com
Get country code with python
Towards the retirement of Python2
About the ease of Python
Get the number of digits
Explain the code of Tensorflow_in_ROS
2.x, 3.x character code of python
[Python] Get the previous month
Stop Omxplayer from Python code
About the features of Python
The Power of Pandas: Python
Try to get the function list of Python> os package
Get your heart rate from the fitbit API in Python!
[Maya Python] Crush the contents of the script 3 ~ List unknown Plugins
[Maya Python] Crush the contents of the script 1 ~ Camera Speed Editor
Get the number of specific elements in a python list
Get the value while specifying the default value from dict in Python
The process of making Python code object-oriented and improving it
[Python] Get the script execution directory with an absolute path
System trade starting with Python3: Get the latest program code