What is the order in which the Windows command prompt executes files with the same name, but different extensions?
For example, I have a bunch of executable files: something.cmd
, something.bat
and something.exe
. Which of these would be executed when I typed something
into a command prompt (given they were on the path, etc.)? If that file did not exist which one would then be executed?
Is there a reference that describes this?
BAT is the batch file that is used in DOS, OS/2 and Microsoft Windows. CMD files are newer version came into existence for batch files. The older systems will not know about CMD files and will run them partially which will throw an error for the batch files saved as CMD.
Try using the conditional execution & or the && between each command either with a copy and paste into the cmd.exe window or in a batch file. Additionally, you can use the double pipe || symbols instead to only run the next command if the previous command failed.
Command Prompt, also known as cmd.exe or cmd, is the default command-line interpreter for the OS/2, eComStation, ArcaOS, Microsoft Windows (Windows NT family and Windows CE family), and ReactOS operating systems.
To run a script file with Command Prompt on Windows 10, use these steps: Open Start. Search for Command Prompt, right-click the top result, and select the Run as administrator option. Type the following command to run a Windows 10 batch file and press Enter: C:\PATH\TO\FOLDER\BATCH-NAME.
Okay, I did some quick experimentation based on some other searches I had going.
The gist is that the order of the commands is dependent on the order the extensions are stored in the PATHEXT
environment variable. So initially I had:
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.RB;.RBW
and for the example above the order in which it would run it was:
something.exe
something.bat
something.cmd
Changing the order which they were defined in the PATHEXT
environment variable did indeed change the order in which they were executed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With