7-Zip Batch Execution Failure Logs Explained
By default, 7-Zip does not create a standalone diagnostic log file when a task fails during a batch script execution. Instead, diagnostic data is delivered through standard console streams, return codes (exit codes), and, in the event of an unhandled crash, Windows Event Viewer entries. This guide explains the diagnostic outputs generated by 7-Zip, the meaning of its specific exit codes, and how to capture actionable logs in batch environments.
Default Console Output (Stdout and Stderr)
When executed via the command line (7z.exe or
7za.exe), 7-Zip writes operational messages directly to
standard streams rather than disk:
- Standard Output (stdout): Displays normal operational activity, processed file lists, compression ratios, and informational warnings.
- Standard Error (stderr): Displays critical failure messages, such as missing files, permission denials, invalid switches, or archive corruption.
If a batch script does not explicitly redirect these streams to a file, the output disappears once the command prompt window closes.
7-Zip Exit Codes
When 7-Zip terminates, it returns an integer exit code to the
operating system. In Windows batch scripts, this is captured via the
%ERRORLEVEL% variable. These codes represent the primary
diagnostic indicator of the failure:
- 0 (Normal): Operation completed successfully; no errors encountered.
- 1 (Warning): Non-fatal error. Some files could not be read or were locked by other processes, but the archive was still generated.
- 2 (Fatal error): Critical failure. The process halted due to severe issues, such as a corrupt archive, incorrect password, disk full condition, or hardware failure.
- 7 (Command line error): Invalid syntax, unrecognized parameters, or conflicting command switches.
- 8 (Not enough memory): The system ran out of RAM required for the selected compression dictionary size or thread count.
- 255 (User stopped): The process was manually
interrupted by the user (e.g., via
Ctrl + C).
Windows Event Viewer Logs
If 7z.exe crashes unexpectedly rather than exiting
cleanly with an error code, Windows records the event in the operating
system logs:
- Log Location:
Windows Logs>Application - Event ID 1000 (Application Error): Indicates an unhandled exception or access violation, listing the faulting module, exception code, and fault offset.
- Event ID 1001 (Windows Error Reporting): Contains crash dump metadata forwarded for troubleshooting.
Normal execution failures (such as wrong passwords or missing target paths) do not trigger Windows Event logs.
Generating Custom Diagnostic Logs in Batch
To ensure failure diagnostics are retained for analysis, batch scripts must manually redirect console streams and evaluate error levels.
A standard implementation to capture complete diagnostics involves:
@echo off
"C:\Program Files\7-Zip\7z.exe" a -tzip "C:\backup\archive.zip" "C:\data\*" > "C:\logs\7zip_output.log" 2>&1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% NEQ 0 (
echo 7-Zip failed with exit code %EXIT_CODE% >> "C:\logs\7zip_output.log"
)The > "C:\logs\7zip_output.log" 2>&1 operator
merges standard error and standard output into a single persistent text
log, ensuring all diagnostic messages are preserved for review.