This is very useful.
Watch also this video in this post.
look for the environmental variable of the system (not of the account).
This window will appear, click where the arrow points
Select path and then modify
Click on new, then write the path where you will put your batch files, press ok.
You are done.
Now let’s see how to create a batch file
Let’s say we wanto get to google with a command on the cmd. Let’s say you have used the D:\bat path like me above. Open the notepad and write the google address.
Save the file like below.
Save the file in D:\bat as google.bat
Now you can also close the window.
Get the cmd
For example you can write cmd in the search bar and click on command prompt above.
Something like this will appear
Write google (the name you gave to the batch file) and press Enter.
Guess what? The page of google in Chrome will appear.
This is cool. You can create any command to do all that you can do with the command of the cli cmd.
As we got the superpower of knowing python, we can create a command to run a script that we made in the batch file, so that with a simple command anywhere (not having to do it in the specific folder where the script is) we can run the python file.
Example of running a python file in a batch file to execute it everywhere with a command.
Let’s make a simple python script
Let’s save this on in D:\python\snippets
We wrote the command to run the python script in the batch file
Now let’s create a batch file like this below and save it in D:\bat as before with the name message
Now we can run the command message in the cmd from everywhere and the python script will be executed
So, you can do a lot of things this way to save your time when you want to execute some python script, open the browser at a certain page and all you can do with the cmd, that is QUITE A LOT. You just need your imagination to use it at your service.
So, have fun, goodbye.
Subscribe to the newsletter for updates
Tkinter templates
My youtube channel
Twitter: @pythonprogrammi - python_pygame