windows 命令提示符执行同名文件的顺序(a.bat vs a.cmd vs a.exe)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/605101/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Order in which command prompt executes files with the same name (a.bat vs a.cmd vs a.exe)
提问by Daemin
What is the order in which the Windows command prompt executes files with the same name, but different extensions?
Windows 命令提示符执行名称相同但扩展名不同的文件的顺序是什么?
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?
例如,我有一堆可执行文件:something.cmd
,something.bat
和something.exe
. 当我输入something
命令提示符时(假设它们在路径上等),哪些会被执行?如果该文件不存在,那么将执行哪个文件?
Is there a reference that describes this?
有没有描述这个的参考资料?
回答by Daemin
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 环境变量中的顺序。所以最初我有:
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.
更改它们在 PATHEXT 环境变量中定义的顺序确实会更改它们的执行顺序。