findstr退出代码/ errorlevel

时间:2015-08-04 13:41:19

标签: cmd exit-code findstr errorlevel

我有一个使用findstr的程序,当找到该字符串时errorlevel返回0,当找不到该字符串时,errorlevel返回{{ 1}}。好吧,我可以解决这个问题。

问题出在哪里,我找不到任何关于每个1errorlevel的含义的官方文档。我需要知道findstr的任何其他内容是否可以返回findstr errorlevel,或者如果找不到该字符串,它只会返回1

首选链接到“官方”文档,如果有,但任何输入都将非常感谢。

提前致谢!

2 个答案:

答案 0 :(得分:9)

http://ss64.com/nt/findstr.html说:

FINDSTR will set %ERRORLEVEL% as follows:

0 (False) a match is found in at least one line of at least one file.
1 (True) if a match is not found in any line of any file, (or if the file is not found at all).
2 Wrong syntax 
An invalid switch will only print an error message in error stream.

答案 1 :(得分:2)

在Dos 6.22帮助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.
│
│You can use the ERRORLEVEL parameter on the <If> command line in a batch
│program to process exit codes returned by FIND.