This post is about linking a Python script to a batch file(.bat).
You will need to get the path of the python .exe file and the path of the python script file (.py ). I use NotePad++ to write the python code and the batch file. The python code will open a specific image determined by the path of the image.
The purpose of executing a Python script through a batch file is for convenience. For example, you need to run some tasks everyday and by including the python scripts in the batch file, all you need to do is to run it.
@echo off "C:\Python\Python37-32\python.exe" "C:\Users\Linawati\Documents\ACCS\OpenCV\OpenImage.py" pause
The ‘@echo off’ is optional and by putting it prevent the content of the batch file to be displayed in the command prompt. Without ‘@echo off’ the batch file still works.
So the steps are:
- Write the code using text editor and save the file with .py extension
- Write the batch file as per above example: path of python.exe, followed by path of Python script, then type ‘pause’ in the next line. Save the batch file with .bat extension.