What is the reason for “X is not recognized as an internal or external command, operable program or batch file”?

前端 未结 2 1361
后悔当初
后悔当初 2020-11-21 06:19

I have a one-line snippet that works perfectly in the command line, but fails and throws up errors when I run it as part of a batch script.

The below commands behave

2条回答
  •  长发绾君心
    2020-11-21 07:08

    Most probably, you messed around with the PATH variable. Perhaps you are overwriting it somewhere else in your script. Since sort is an external command, opposed to all the others in your command line like for, dir, rd, which are cmd-internal commands, the PATH variable is needed to find the command. If PATH is not defined, external commands are searched in the current working directory only. There is also a PATHEXT variable that is needed to define standard file extensions for executables, like .com, .exe. So when sort appears in command prompt or in a batch file, the system searches the current working directory and all directories specified by the PATH variable for a file with the base name sort and one of the extensions specified by PATHEXT. The command sort is actually called sort.exe and is usually located in C:\Windows\System32.

提交回复
热议问题