2015-08-04 15 views
7

Ho un programma che utilizza findstr, e quando la corda viene trovato i rendimenti errorlevel0 e quando la stringa non viene trovata la errorlevel rendimenti 1. Va bene, va bene, posso occuparmene.codici di uscita FINDSTR/errorlevel

Dove si trova il problema non riesco a trovare alcuna documentazione ufficiale su cosa ogni errorlevel significa per findstr. Ho bisogno di sapere se qualcos'altro per findstr potrebbe mai restituire un errorlevel di 1, o se restituisce solo 1 quando la stringa non viene trovata.

I collegamenti alla documentazione "ufficiale" sono preferiti, se ce ne sono, ma qualsiasi input sarebbe molto apprezzato.

Grazie in anticipo!

risposta

7

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

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. 
+0

Grazie mille, esattamente quello che stavo cercando! –

2

È documentato nel comando Dos 6.22 Help per 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. 
+0

Questo si applica anche a 'findstr '? –

+0

Sì. Ho cercato un riferimento più recente per 12 anni. Ho Dos 6.22 e OS/2 Warp 4 (si dice _ Restituisce 0 per il completamento normale_). – bill

Problemi correlati