Home » Uncategorized » Turning scripts into independant commands on Windows

Turning scripts into independant commands on Windows


Dynamic language interpreters (“script engines”) in Windows don’t normally install in such a way that once you write a script, you can simply call it on the command line.

If you have a script named hello.py, you cannot just type “hello” at the command line and hope it will work. It won’t.

The file extension has to be registered as an executable file, and the default program for opening the script must be its appropriate interpreter.


  1. Create a directory at C:mybin
  2. right-click on the My Computer icon on your desktop or in the Windows Start menu (in Win7 it is just called “Computer” and select ‘Properties’)
  3. Click on the Advanced Settings button, and then on the Environment Variables button
  4. Edit the PATH variable in System Variables, add the following to the end of its data:

    (note: the semi-colon ‘;’ is important)

  5. save and return to the desktop.

We now assume that the scripts you want to run get saved to C:mybin

You will need to use the `assoc` and `ftype` commands to achieve this

1) Associate a file extension to a pattern name

assoc .jar=jarfile

2) Define the handling in the pattern:

ftype jarfile="C:jsdk-1.6.0_18binjava.exe" -jar "%1" %*

Surround the path to the executable with quote marks as best practice.

Surround the %1 argument with double quotes as well – this is the path to your runnable file; if it has spaces in its path, you need the double quotes to keep it whole.

Do not surround %* with quotes, this represents all the arguments that were initially specified on the command line.

Posted in Uncategorized

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.