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.