Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 627 Vote(s) - 3.49 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Catch an error inside a batch file (7-zip)

#1
I have a batch file in which I execute the following line to list the contents of an archive:

"\Program Files\7-Zip\7z.exe" l "\Backup Google Docs.7z"

The archive is intentionally corrupted.

cmd.exe displays this:

![enter image description here][1]


[1]:


How can I catch this error in my code?
Reply

#2
Any program's exit code is stored in the `%ERRORLEVEL%` variable in a batch script.

From the 7-zip manual:

7-Zip returns the following exit codes:

Code Meaning
0 No error
1 Warning (Non fatal error(s)). For example, one or more files were locked by some other application, so they were not compressed.
2 Fatal error
7 Command line error
8 Not enough memory for operation
255 User stopped the process


So: you 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 that `%ERRORLEVEL%` is greater or equal than N, therefore you should put them in descending order.
Reply

#3
Check if the ERRORLEVEL is set to 1 just after the call to 7z.exe and react appropriately. The ERRORLEVEL is the exit code from the last program that was run. An exit code of 1 or more indicates an error while zero indicates success. The IF ERRORLEVEL command checks if the exit is greater than or equal to the argument so IF ERRORLEVEL checks for an error level of one or more.

Here is an example:

"\Program Files\7-Zip\7z.exe" l "\Backup Google Docs.7z" > nul
IF ERRORLEVEL 1 goto ziperror
@echo 7-Zip worked
goto :eof

:ziperror
@echo 7-Zip failed
goto :eof
Reply



Forum Jump:


Users browsing this thread:
3 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through