Need to make an auto exec batch file [closed]

You could specify an atexit handler in your python script:

import atexit
import os

def exit_handler():
    os.system("C:/Path/To/batch.bat")

atexit.register(exit_handler)

Where test.bat contains:

Python C:/Path/To/python.py

However, this will also cause the script to start up again if it exits legitimately.

Perhaps if you could identify what exit code is sent when it exits “randomly”, you can check for that exitcode in atexit and start the batch file up if it matches your problematic exit code.

Leave a Comment