Коды выхода findstr/уровень ошибки

У меня есть программа, использующая findstr, и когда строка найдена, errorlevel возвращает 0, а когда строка не найдена, errorlevel возвращает 1. Хорошо, это нормально, я могу с этим справиться.

Проблема в том, что я не могу найти никакой официальной документации о том, что означает каждый errorlevel для findstr. Мне нужно знать, может ли что-нибудь еще для findstr вернуть errorlevel из 1, или же оно возвращает 1 только тогда, когда строка не найдена.

Предпочтительны ссылки на «официальную» документацию, если таковые имеются, но любой вклад будет принят с благодарностью.

Заранее спасибо!


person Saltz3    schedule 04.08.2015    source источник


Ответы (2)


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.
person Stephan    schedule 04.08.2015

Это задокументировано в справке 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.
person bill    schedule 04.08.2015
comment
Это также относится к `findstr'? - person Saltz3; 04.08.2015
comment
Да. Я искал более свежую ссылку в течение 12 лет. У меня Dos 6.22 и OS/2 Warp 4 (там написано Возвращает 0 для нормального завершения). - person bill; 05.08.2015