Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
452 views
in Technique[技术] by (71.8m points)

windows - Order in which command prompt executes files with the same name (a.bat vs a.cmd vs a.exe)

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...