Windows如何在外壳中找到输入的文件? [英] How does Windows locate files input in the shell?

查看:100
本文介绍了Windows如何在外壳中找到输入的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网站上寻找了这个问题,但似乎从未有人问过,所以我想与任何寻找它的人分享答案.

I looked for this question over the site but it looks like it's never been asked, so I thought I would share the answer to anyone looking for it.

问:当我通过外壳执行函数或批处理文件在cmd.exe中输入可执行文件的名称时,Windows如何找到要调用的外部可执行文件?

Q: When I input executables files' name in cmd.exe, through shell-execution functions or from a Batch file, how does Windows locate the external executable file to be called?

推荐答案

我不理解"shell执行功能"是指什么,因此我将忽略它.

I do not understand what "shell-execution function" is referring to, so I will ignore it.

但是从CMD.EXE命令行或批处理文件启动可执行文件的规则如下:

But the rules for launching an executable from the CMD.EXE command line, or from a batch file are as follows:

  1. 如果为可执行文件(绝对或相对)指定了路径,则仅搜索该路径.

  1. If a path is specified for the executable (absolute or relative), then only that path is searched.

如果仅指定可执行文件名称(可能是扩展名),则

If only the executable name (and possibly extension) is specified, then

  • 首先搜索当前文件夹

  • First search the current folder

然后在PATH环境变量中搜索文件夹(按列出的顺序)

Then search folders in PATH environment variable (in order listed)

在搜索的每个文件夹中,使用提供的扩展名.如果没有提供文件扩展名,请查找与在PATHEXT环境变量中找到的扩展名匹配的文件(按列出的顺序).

Within each folder searched, use the provided extension. If no file extension is provided, then look for files that match extensions found in PATHEXT environment variable (in order listed).

找到的第一个匹配文件是被执行的文件.

The first matching file found is the one that gets executed.

编辑

David Candy向我指出了一些过时的NT文档,它们精确地概述了搜索过程,并且基本上与我上面编写的内容匹配.请参见从NT Shell启动应用程序

David Candy has pointed me to some outdated NT documentation that precisely outlines the search process, and it essentially matches what I have written above. See Launching Applications from the NT Shell

如果有人可以发布指向类似CMD.EXE文档的链接以获取最新版本的Windows,尤其是如果它是由Microsoft编写的,我将非常喜欢.请注意,上面链接的NT文档不是由Microsoft编写的,即使它们发布在他们的网站上.

I'd love it if anyone could post links to similar CMD.EXE documentation for more recent versions of Windows, especially if it was written by Microsoft. Note that the NT doc linked above was not written by Microsoft, even though it is posted on their site.

这篇关于Windows如何在外壳中找到输入的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆