Windows cmd command Search order

Source: Internet
Author: User

To execute a command without a suffix in cmd (without a path), first search in a system command (such as CD, DIR, etc.) with no prefix, and execute the command if found.

(dir is a system command with no suffix, so take precedence, ignoring Dir.exe in the current directory)

If no suffix is found in the system command, the current directory looks for the command +.exe,. msc,. bat, and other suffixes of the executable file or batch file , if found is executed, if not found, then in the environment variable those directories in the above rules search .

(The system's tasklist command is actually tasklist.exe, so it cannot be found in a system command with no suffix, and then searches the current directory for the tasklist named executable "suffix. exe, or. bat,. msc" There is just one tasklist.exe in the current directory)

(The current directory does not exist Tasklist.exe or Tasklist.bat, tasklist.msc and other executables, so in the environment variable search, found in the system directory Tasklist.exe execution)

If the command entered in cmd has a suffix (without a path), the file is searched in the current directory first , if it is an executable file or a batch file , the file is executed, If it is a different generic file, open it with the default program associated with that type of file ;

(Put Tst.exe, Tst.exe.exe, Tst.txt, tst.txt.exe four files in the cmd current working directory, and also put four files with the same name in the directory D:\Program Files\tencent\qq\bin that have been added to the environment variable.) , but the exe file output and TXT file store the text is different, showing the corresponding file name and location. As shown in the above two diagram, the Tst.exe and Tst.txt commands are executed in CMD, the result is tst.exe in the current directory and the tst.txt of the current directory are opened, and the table is first searched for the file in the current directory. )

If the file does not exist in the current directory, look in the current directory for the existence of a file named after the file name + executable or batch file suffix (. exe,. bat,. msc, etc.) and execute it if found;

(Tst.exe and Tst.txt in the current directory are removed, then the Tst.exe and Tst.txt commands are executed, as shown in the previous two figure, respectively, the Tst.exe.exe and Tst.txt.exe programs in the current directory were executed, indicating that the file could not be found in the current directory. Name + executable file or batch file suffix named file to execute, rather than go to the environment variable to find the file)

If neither of the above is found in the current directory, search in those directories set by the environment variable in the order listed above . first, according to the cmd command to give the exact file name lookup, if any, is the program or batch is executed, is the other file is opened with the default program;

(Tst.exe.exe and Tst.txt.exe in the current directory are also removed, CMD executes the tst.exe and Tst.txt commands, the result executes the Tst.exe program in the directory that has been added to the environment variable, and the Tst.txt file in that directory is opened, stating that if the current directory in CMD does not find the File or executable such as the file name,. exe, and then go to the environment variable to find the file)

If the file is not found in the environment variables directory, then in the environment variables directory, look for files that have the file name + executable or batch file suffix (. exe,. bat,. msc, and so on) that are executed if found.

If not, then have to error, the command is not recognised as a internal or external command, operable program or batch file.

Of course, if the cmd command with a path, it is obvious that only in the specified directory to find the file, but not to the environment variable to find, if the file name does not have a suffix, the same as the first case, in the specified directory to find the name of the executable file or batch file execution, no error is found, if there is a suffix, is executed or opened with the default program, if it does not exist, look for the file name + executable file or batch file suffix file to execute, can not find an error.

PS: is also a voluminous hard to the heart of painstaking efforts. Did I drill too thin? Obsessive-compulsive disorder, which is the biggest stumbling block and obstacle in my learning process, seriously affects the efficiency. What is so complicated about the actual application? The command also has a suffix, the file name is also a succession of multiple suffixes, is really too much. The actual application is generally very simple, the file name + 1 suffix, it is not likely to have this deliberately named, the cmd command is generally the first case, without suffix, execute the system command or the current directory or environment variable directory executable file or batch file. But I do have obsessive-compulsive disorder, not to think so careful and uncomfortable.

Windows cmd command Search order

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.