China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-01 14:44
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Solved: About the name conflict problem between the tree command and the tree batch file View 2,225 Replies 2
Original Poster Posted 2005-11-29 14:35 ·  中国 辽宁 大连 联通
新手上路
Credits 14
Posts 5
Joined 2005-11-15 15:12
20-year member
UID 45299
Gender Male
Status Offline
tree/f>>tree.txt

The above is what I wrote, and then I saved it as a.bat format.
I named this bat as a.bat.
Double-clicking to execute can display the tree structure of all files in the current folder.

D:.
│ a.bat
│ 0401801BackAction.java
│ 0401801CsvAction.java
│ 0401801CsvJavaBean.java
│ 0401801DepotchangeAction.java
│ 0401801DepotchangeJavaBean.java
│ 0401801Form.java
│ 0401801InitAction.java
│ 0401801InitJavaBean.java
│ 0401801PrintAction.java
│ 0401801PrintJavaBean.java
│ 0401801SearchAction.java
│ tree.txt

└─0401801
WEE0401801.jsp

But if I change the name of the bat file to tree.bat,
after double-clicking to execute, the content of the newly generated tree.txt file is as follows:

D:\040180>tree/f1>>tree.txt



I don't know what the reason is. Is there any expert who has time to explain it to me, thank you! !!!

[ Last edited by willsort on 2005-11-30 at 19:54 ]
Floor 2 Posted 2005-11-29 16:05 ·  中国 山西 大同 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
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 ]
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 3 Posted 2005-11-30 17:56 ·  中国 辽宁 大连 联通
新手上路
Credits 14
Posts 5
Joined 2005-11-15 15:12
20-year member
UID 45299
Gender Male
Status Offline
Thanks a lot!! Learned a lot
Originally only knew it was a Mingzi problem
But didn't know the specific principle
Now I understand, thank you for the answer from the person above

[ Last edited by undiligent on 2005-11-30 at 17:59 ]
Forum Jump: