Capture Stderr Separately From Stdout in Unrar

Capturing standard error (stderr) separately from standard output (stdout) when using unrar is essential for debugging, error handling, and clean logging in automated scripts. This guide demonstrates how to isolate both streams using standard command-line redirection operators in Linux, macOS, and Windows environments.

Understanding Output Streams

Command-line programs use two distinct data streams to display text:

  • Standard Output (stdout / File Descriptor 1): Normal runtime information, such as file extraction progress and lists of extracted files.
  • Standard Error (stderr / File Descriptor 2): Warnings, corrupt archive alerts, missing password prompts, and fatal errors.

By default, both streams are combined and printed directly to your terminal. You can split them using stream redirection operators.

Redirecting Stderr and Stdout to Separate Files

To save normal extraction logs to one file and error messages to another, use the > (or 1>) and 2> operators:

unrar x archive.rar > stdout.log 2> stderr.log
  • > stdout.log: Directs normal extraction output to stdout.log.
  • 2> stderr.log: Directs error messages to stderr.log.

If an error occurs—such as a wrong password or a corrupt volume—the details will be isolated in stderr.log, leaving stdout.log uncluttered.

Capturing Only Stderr While Discarding Stdout

If you only care about catching errors and want to discard the verbose extraction list, redirect stdout to /dev/null (on Linux/macOS) or NUL (on Windows):

Linux and macOS

unrar x archive.rar > /dev/null 2> error.log

Windows (CMD / PowerShell)

unrar x archive.rar > NUL 2> error.log

Displaying Stdout on the Screen While Logging Stderr

If you want to monitor the extraction progress live in the terminal while silently capturing any errors to a file, simply redirect file descriptor 2:

unrar x archive.rar 2> error.log

Because stdout is not redirected, progress updates will continue to appear on your screen, while any errors will be written directly to error.log.

Using Unrar’s Native Quiet Switch

unrar provides a built-in flag to suppress standard output: -inul. When this switch is active, unrar disables all normal console messages, sending only fatal errors to the terminal (stderr):

unrar x -inul archive.rar 2> error.log

Combining the -inul flag with 2> error.log ensures that standard output is suppressed at the application level, while actual errors are preserved cleanly in your error log.