How to open a .exe file using an abbreviation in CMD
How to open a .exe file using an abbreviation in CMD
I want to start an .EXE file using one command, an abbreviation or alias you could say.
For example, I want to open Far Manager using an alias, I have at first to CD into the path, which is c:UsersmyUserdesktopfarfar.exe
.
I know about the set "alias=myCommand param1 param2"
but the problem is I want a single command to open up the application, for example Atom and VSCode have this feature, if I type atom or code in cmd it will open up. so I want to set a single command to open up the application without having to changing the directory into it at first and then use the start
command.
c:UsersmyUserdesktopfarfar.exe
set "alias=myCommand param1 param2"
start
4 Answers
4
One way to do this is to add the folder path for the executable to your PATH
environment variable.
PATH
In Windows 7, 8 and 10, you can:
Alternatively (also for older versions of Windows):
In Windows 10 (and possibly 8?), you will see an edit window that makes it easy to add a path. In prior editions of Windows, you will see a text box edit window. Add the folder path to the end, preceded by a semi-colon: ;c:UsersmyUserdesktopfarfar.exe
;c:UsersmyUserdesktopfarfar.exe
The simplest solution would be to put your code into a .bat
file,
then add its folder into the PATH environment variable (or store the file into
a folder that is already in the PATH).
.bat
To avoid seeing the commands execute, start the file with an @echo off
line.
@echo off
One more option is to use doskey
, which gives a macro function in cmd
:-
doskey
cmd
doskey MacroName=pushd c:UsersmyUserdesktopfar $T start far.exe $ popd
You can add this command to a cmd
start-up file.
cmd
Yet another option is to set the directory and program name in a program shortcut (eg far.lnk
) which you can create in a directory already in your path. Such files can be called direct from cmd
.
far.lnk
cmd
If you want to be able to start a command without having to specify the full path, you have to include the directory in your PATH
variable. You can see the current PATH
with
PATH
PATH
echo %PATH%
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
This would definitely be my approach too.
– LPChip
Aug 29 at 18:50