How to Pause Unrar on CRC Error
This guide explains how to pause the extraction process when
unrar encounters a CRC (Cyclic Redundancy Check) error.
Because the unrar utility does not possess an internal
command-line switch to halt and wait for user input specifically during
a checksum mismatch, you must handle the pause by capturing
unrar's operational exit code in a shell or batch
script.
Understanding the Unrar CRC Exit Code
When unrar unpacks an archive and discovers that a
file's checksum does not match, it terminates or finishes the run with
an exit status of 3.
Standard unrar exit codes include:
- 0: Successful operation
- 1: Non-fatal error / warning
- 2: Fatal error
- 3: CRC error occurred during unpacking
- 255: User stopped the process
Windows Command Prompt / Batch Command
In Windows, use the %errorlevel% variable to detect exit
code 3 and invoke the pause command:
unrar x archive.rar
if %errorlevel% equ 3 pauseTo run this as a single-line command directly in the command prompt:
unrar x archive.rar & if errorlevel 3 if not errorlevel 4 pauseLinux and macOS (Bash) Command
In a Unix-like environment, evaluate the $? variable
immediately after executing unrar to prompt the user to
continue:
unrar x archive.rar
if [ $? -eq 3 ]; then
read -p "A CRC error was detected. Press [Enter] to continue..."
fiAs a single-line command:
unrar x archive.rar || [ $? -eq 3 ] && read -p "CRC error encountered. Press Enter to pause..."Preventing File
Deletion on CRC Errors (-kb)
By default, unrar deletes damaged files after
encountering a CRC mismatch. If your goal in pausing is to inspect or
salvage corrupt data, include the -kb (keep broken
extracted files) switch:
unrar x -kb archive.rarCombining -kb with exit-code handling preserves the
damaged file on disk while still halting your terminal script when exit
code 3 is returned.