Inside a batch file on Windows, I use 7-zip like this:

...\right_path\7z a output_file_name.zip file_to_be_compressed

How could I check the exit code of 7z and take the appropriate action ?

link|improve this question

feedback

1 Answer

up vote 5 down vote accepted

Test for a return code greater than or equal to 1:

if ERRORLEVEL 1 echo Error

or

if %ERRORLEVEL% GEQ 1 echo Error

or test for a return code equal to 0:

if %ERRORLEVEL% EQU 0 echo OK

You can use other commands such as GOTO where I show echo.

link|improve this answer
I tried your code. I got the following error: 0 was unexpected this time. – Misha Moroshko Oct 1 '10 at 5:13
1  
@Misha: You may have tried it with the percent signs the way I originally posted it. Try it without them or try the other versions I added. – Dennis Williamson Oct 1 '10 at 5:24
Great, thanks a lot !! – Misha Moroshko Oct 1 '10 at 11:53
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.