views:

362

answers:

2

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, 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?

I know this is a simple question but I'd like to know if there's a reference someone has that describes this.

+2  A: 

I believe this is what you are looking for

http://support.microsoft.com/kb/35284

Peter LaComb Jr.
for reference, google .bat .com .exe order
Peter LaComb Jr.
It does somewhat, but it doesn't say if it prefers cmd to bat, etc. Also it's for the command.com interpreter, the 16bit one.
Daemin
.cmd files aside, that order still stands (MS wouldn't break compatibility THAT badly). I don't have a good reference to support that though. I'd suspect that .CMD files would come after .bat
Peter LaComb Jr.
+3  A: 

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.

Daemin
Hing: accept own answer.
Joshua