0

Might be a silly question. I have seen 3rd party software work directly through the software's name. Like for example, You can just run a command "docker " on CMD and it works. So I was wondering if i can do the same for my own python programs. Like.. if I have a program "prg1", i should be able to run command "prg1" and the program should be launched. Is it possible??

Thanks for the answer in advance

2 Answers2

0

In Linux, there is what is called a shebang, on the first line of a file, defining which interpreter should be used for a script, it looks like this for /bin/bash, for example:

#!/bin/bash

myscript

In Windows, you cannot do this directly, you should use an environmental variable called PATHEXT instead, as described here.

To quote that answer, your variable contains a chain of extensions it recognizes:

PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

You must add the extension of your script to the variable (explained here), and then associate it with the interpreter you want to use (in your case, your Python one):

ASSOC .foo=FooScript
FTYPE FooScript=foorunner.exe %1 %*

(Note that these commands permanently change the association, so keep that in mind if the path to your Python interpreter changes for example).

0

What you want is the path variable. The path variable is where the shell or command line will search for programs to execute. What you want to do is add the directory containing the executable or file to the system path.

In windows this can be achived by searching "Edit the system envirnoment variables", click on "environment variables" select "Path". Select "Edit". Select "New". Add the path to the direcory containing the path, select "Ok" X 3.

On linux you can run the command "PATH=$PATH:/my/new/path"

If it works, you shoule be able to run, in your case "prg1", any executable added to the new path.

As far as "custom" goes you can make a foulder called "path" add it to path, and add batch or shell scripts inside, that launch the program, to run these scripts, just type the name in terminal and run it.

Reisen
  • 1