windows - Catch an error inside a batch file (7-zip) -


i have batch file in execute following line list contents of archive:

"\program files\7-zip\7z.exe" l "\backup google docs.7z" 

the archive intentionally corrupted.

cmd.exe displays this:

enter image description here

how can catch error in code?

any program's exit code stored in %errorlevel% variable in batch script.

from 7-zip manual:

7-zip returns following exit codes:  code meaning  0 no error  1 warning (non fatal error(s)). example, 1 or more files locked other application, not compressed.  2 fatal error  7 command line error  8 not enough memory operation  255 user stopped process  

so: can do:

"\program files\7-zip\7z.exe" l "\backup google docs.7z" if errorlevel 255 goto:user_stopped_the_process if errorlevel 8 goto:not_enough_memory if errorlevel 7 goto:command_line_error if errorlevel 2 goto:fatal_error if errorlevel 1 goto:ok_warnings 

caution, if errorlevel n checks %errorlevel% greater or equal n, therefore should put them in descending order.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -