In this one I am going to be showing you how you can run your python scripts from the terminal in directory on windows.
But first we shall look at what a PATH variable means and what ENVIRONMENTAL variables mean
Environmental Variable
An environment variable is a variable whose value is set outside the program, typically through functionality built into the operating system or microservice. An environment variable is made up of a name/value pair, and any number may be created and available for reference at a point in time.
PATH Variable
The PATH variable is an environment variable that contains an ordered list of paths that Linux will search for executables when running a command. Using these paths means that we do not have to specify an absolute path when running a command.
Now that we know what these terms mean we can get into the actual work
First step is to write our custom script, in this case I am using a script I developed to kill annoying tasks because task manager sometimes does not respond
import os
import sys
if len(sys.argv) < 2:
print("[!] Usage: kill.py 'program name'")
sys.exit()
program = sys.argv[1]
print(f"[*] Killing {program}")
os.system(f'taskkill -f -im {program}.exe')
sys.exit()
Next step is to create a folder for our custom scripts and add the folder path to environmental variables
After copying folder path click windows button and
Next step click on environmental variables
click on path and then edit at the bottom
click on new and then paste in the path to our custom folder
And voila we are ready to go. So to test this we open a new terminal and type out the name of our script in this case kill.py
you should see the error output
Anyways we go ahead and test this
Use this to automate your boring tasks, Happy Coding Everyone :)
Top comments (0)