Short tips for executing complex commands in cmd using .bat files (Windows)

Short tips for executing complex commands in cmd using .bat files (Windows)

We are all witnessing cases where we forgot a Python syntax for a specific situation. Then we need to go to StackOverflow or Google and spend valuable time finding something we forgot.

Let's see an example: we have created a virtual environment and installed ipykernel. Then we must print this command in cmd to create a kernel specification:

python -m ipykernel install --user --name mykernel --display-name "My Kernel"

Unfortunately, every time we try to remember it, we fail and spend much time finding the answer. So here is a helpful tip to follow:

  1. Create a txt file and print the following:

@echo off
python -m ipykernel install --user --name mykernel --display-name "My Kernel"f        

2. Save the file as a .bat file with a short and easy name to remember every time. For example, ipykernel_specification.bat.

3. Add the file to the PATH. For instance, if the file is in the MyFolder directory:

setx PATH "%PATH%;C:\MyFolder"        

And that's it! Now, instead of typing the entire command every time you need it, simply run ipykernel_specification in cmd, and you are done !!!


To view or add a comment, sign in

More articles by DIMITRIOS C. THEODOROPOULOS, PhD

Explore content categories