先说一下 FIND 的退出码说明
FIND exit codes
The following list shows each exit code and a brief description of its meaning:
0
The search was completed successfully and at least one match was found.
1
The search was completed successfully, but no matches were found.
2
The search was not completed successfully. In this case, an error
occurred during the search, and FIND cannot report whether any matches
were found.
建立一个只有一行 ok 内容的文件 txt ,用 FIND 不同的参数来执行查看结果和退出码:
D1.
find "ok" txt
---------- TXT
ok
exitcode = 0
//找到了要找的字符,返回退出码0,正常
D2.
find/v "ok" txt
---------- TXT
exitcode = 0
//按理,这里应该是没有找到要找的字符,为什么返回的退出码是0 ?难道一个不存在的行也算是找到?但是,同样也是“找到”,下面第四个例子返回的却是1
D3.
find "w" txt
---------- TXT
exitcode = 1
//没有找到要找的字符,返回的退出码是1,正常
D4.
find/v "w" txt
---------- TXT
ok
exitcode = 1
//找到了不包含 w 字符的行,也就是找到要找的字符,按理,这里的退出码应该是0,它为什么返回的是1?
现在,在把 txt 文件内容修改一下,增加一行 not 内容,再按照上述参数执行一下,看看结果:
D5.
find "ok" txt
---------- TXT
ok
exitcode = 0
//
D6.
find/v "ok" txt
---------- TXT
not
exitcode = 0
//
D7.
find "w" txt
---------- TXT
exitcode = 1
//
D8.
find/v "w" txt
---------- TXT
ok
not
exitcode = 1
//
具体我就不解释了,和前面一样,退出码的顺序同样也为 0 0 1 1 。我在 MS-DOS 6.22 和 MS-7.10 下的 FIND 得出相同的结果。
后来我又测试了下 WindowsXP 下的 FIND ,被测文件内容和参数顺序同上。
只有内容为 ok 的 txt 文件:
X1.
find "ok" txt
---------- TXT
ok
exitcode = 0
//找到了要找的字符,退出码为0,正常
X2.
find/v "ok" txt
---------- TXT
exitcode = 1
//没有找到要找的字符,退出码为1,正常
X3.
find "w" txt
---------- TXT
exitcode = 1
//没有找到要找的字符,退出码为1,正常
X4.
find/v "w" txt
---------- TXT
ok
exitcode = 0
//找到了不包含 w 的行,也就是查找到了要找的内容,退出码为0,正常
现在, txt 文件内容增加 not 一行:
X5.
find "ok" txt
---------- TXT
ok
exitcode = 0
//找到了要找的字符,退出码为0,正常
X6.
find/v "ok" txt
---------- TXT
not
exitcode = 0
//找到了不包含 ok 的行,也是找到了要查找的内容,退出码为0,正常
X7.
find "w" txt
---------- TXT
exitcode = 1
//没有找到要找的字符,退出码为1,正常
X8.
find/v "w" txt
---------- TXT
ok
not
exitcode = 0
//找到了不包含 w 的行,也是找到了要查找的内容,退出码为0,正常
由此看来 DOS 下,确切的说是 MS-DOS 下(其它的 DOS 我还没试)的 FIND 命令的退出码有缺陷,缺陷在于加了 /v 参数后的退出码没有按照本意来返回,也就是我前面 D2 和 D4 的例子,在 Windows XP 下(我的是SP2版的)的 FIND 修正了这个 bug 。其它版本的 Windows 未作测试。
最后注明:为了方便查看退出码和结果重定向到文件,我在 DOS 下的测试环境是 4DOS ,在 Windows 下的命令行环境是 4NT ,我想这应该不会影响什么测试结果。
First, let's talk about the exit code explanation of FIND.
FIND exit codes
The following list shows each exit code and a brief description of its meaning:
0
The search was completed successfully and at least one match was found.
1
The search was completed successfully, but no matches were found.
2
The search was not completed successfully. In this case, an error
occurred during the search, and FIND cannot report whether any matches
were found.
Create a file txt with only one line "ok" content, and execute it with different parameters of FIND to view the results and exit codes:
D1.
find "ok" txt
---------- TXT
ok
exitcode = 0
//Found the character to be found, returned exit code 0, normal
D2.
find/v "ok" txt
---------- TXT
exitcode = 0
//According to reason, there should be no character to be found, why is the returned exit code 0? Does a non-existent line also count as found? But, similarly, it is also "found", but the fourth example below returns 1
D3.
find "w" txt
---------- TXT
exitcode = 1
//No character to be found, returned exit code 1, normal
D4.
find/v "w" txt
---------- TXT
ok
exitcode = 1
//Found the line that does not contain the character w, that is, found the character to be found. According to reason, the exit code here should be 0, why does it return 1?
Now, modify the content of the txt file, add a line "not" content, and then execute it according to the above parameters:
D5.
find "ok" txt
---------- TXT
ok
exitcode = 0
//
D6.
find/v "ok" txt
---------- TXT
not
exitcode = 0
//
D7.
find "w" txt
---------- TXT
exitcode = 1
//
D8.
find/v "w" txt
---------- TXT
ok
not
exitcode = 1
//
I won't explain the specific details. The order of exit codes is also 0 0 1 1. I got the same results under MS-DOS 6.22 and MS-7.10 for FIND.
Later I tested FIND under Windows XP, and the tested file content and parameter order are the same as above.
For the txt file with only content "ok":
X1.
find "ok" txt
---------- TXT
ok
exitcode = 0
//Found the character to be found, exit code is 0, normal
X2.
find/v "ok" txt
---------- TXT
exitcode = 1
//No character to be found, exit code is 1, normal
X3.
find "w" txt
---------- TXT
exitcode = 1
//No character to be found, exit code is 1, normal
X4.
find/v "w" txt
---------- TXT
ok
exitcode = 0
//Found the line that does not contain w, that is, found the content to be searched, exit code is 0, normal
Now, add a line "not" to the content of the txt file:
X5.
find "ok" txt
---------- TXT
ok
exitcode = 0
//Found the character to be found, exit code is 0, normal
X6.
find/v "ok" txt
---------- TXT
not
exitcode = 0
//Found the line that does not contain ok, also found the content to be searched, exit code is 0, normal
X7.
find "w" txt
---------- TXT
exitcode = 1
//No character to be found, exit code is 1, normal
X8.
find/v "w" txt
---------- TXT
ok
not
exitcode = 0
//Found the line that does not contain w, also found the content to be searched, exit code is 0, normal
It can be seen that under DOS, specifically under MS-DOS (I haven't tested other DOS yet), the exit code of the FIND command has a defect. The defect is that the exit code after adding the /v parameter is not returned according to the original intention, that is, the examples D2 and D4 above. In Windows XP (my version is SP2), the FIND has corrected this bug. Other versions of Windows have not been tested.
Finally, it is noted: In order to facilitate viewing the exit code and redirecting the result to a file, my test environment under DOS is 4DOS, and the command line environment under Windows is 4NT. I think this should not affect the test results.