『第 2 楼』:
使用 LLM 解释/回答一下
Re undiligent:
这是一个很典型的因为名字冲突而引起的问题。
在 MSDOS/Windows 中,tree 一般是系统提供的外部命令所使用的。与内部命令不同的是,外部命令与其他的可执行程序相比,不具有更高的名字优先权。这里提供 MSDOS 的可执行体执行优先顺序列表:
1、DOS 宏命令,由 doskey 支持
2、DOS 内部命令,由 command.com 支持
3、DOS 可执行程序(包括外部命令),由可执行程序文件支持
3-1、按照所处路径的优先级排序:用户指定路径、当前路径、%path%所指路径
3-2、按照扩展名的优先级排序: com exe bat
注意:当3-1与3-2遇到冲突时,3-1具有更高的优先级。也就是说,两个同主名的程序,一个是 %path% 路径下的 tree.exe 文件,一个是当前路径下的 tree.bat 文件,此时将优先执行后者。
也就是说,当你的批处理改为 tree.bat 之后,你点击执行它,它会执行 tree /f1 >>tree.txt 这一句,而其中的 tree 并没有被理解为 tree.exe 这个外部命令,而被理解 tree.bat 这个批处理,所以会再次执行 tree.bat 这个批处理自身,如此反复不断地递归执行下去,直到系统内部的调用堆栈用尽而被系统终止。而其命令行显示因为未被 echo off 禁止而被重定向到文件中。
避免此类问题的最好方法就是,不要以系统程序已占用的名字命名自己编写的程序。解决办法:一个是将 tree.bat 改为其他系统未占用的主名;一个是将批处理中的 tree/f 改为 tree.exe/f ;另外,将系统的 tree.exe 改名,同时修改批处理中的调用名,也是一个办法 <img src="images/smilies/face-wink.png" align="absmiddle" border="0">
Last edited by willsort on 2005-11-30 at 19:48 ]
Re undiligent:
This is a very typical problem caused by name conflict.
In MSDOS/Windows, tree is generally the name used by the system-provided external command. Different from internal commands, external commands do not have higher name priority compared with other executable programs. Here is the priority list of executable body execution in MSDOS:
1. DOS macro commands, supported by doskey
2. DOS internal commands, supported by command.com
3. DOS executable programs (including external commands), supported by executable program files
3-1. Sorted by the priority of the path where they are located: user-specified path, current path, path referred to by %path%
3-2. Sorted by the priority of the extension: com exe bat
Note: When there is a conflict between 3-1 and 3-2, 3-1 has higher priority. That is to say, there are two programs with the same main name, one is the tree.exe file in the %path% path, and the other is the tree.bat file in the current path. At this time, the latter will be executed first.
That is to say, after your batch processing is changed to tree.bat, when you click to execute it, it will execute the line tree /f1 >>tree.txt. And the tree in it is not understood as the external command tree.exe, but as the batch processing tree.bat, so it will execute the batch processing tree.bat itself again, and so on, repeatedly recursively until the internal call stack of the system is exhausted and terminated by the system. And its command line display is redirected to the file because it is not prohibited by echo off.
The best way to avoid such problems is not to name the program you write with the name occupied by the system program. Solutions: one is to change tree.bat to other main names not occupied by the system; one is to change tree/f in the batch processing to tree.exe/f; in addition, renaming the system's tree.exe and modifying the call name in the batch processing is also a way ;)
Last edited by willsort on 2005-11-30 at 19:48 ]
|