Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I use 7-Zip to compress files inside a batch file like this:

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

I got the following output:

7-Zip 4.65  Copyright (c) 1999-2009 Igor Pavlov  2009-02-03
Scanning

Creating archive output_file_name.zip

Compressing  file_to_be_compressed

Everything is Ok

Is it possible to disable this output (that is, I don't want anything to be printed)?

share|improve this question

3 Answers 3

up vote 11 down vote accepted

Just add > NUL: to the end of your command.

share|improve this answer
    
Great, thanks !! –  Misha Moroshko Oct 1 '10 at 4:41

It is highly recommended to view status messages in the process. To avoid long messages, display only confirmations:

...\right_path\7z a output_file_name.zip file_to_be_compressed | findstr /b /r /c:"\<Everything is Ok" /c:"\<Scanning" /c:"\<Creating archive"
share|improve this answer
    
Thanks for the findstr solution! It looks like you can somewhat shorten that call by either omitting /b or both the \r and the \< inside the search strings. I'd go with findstr /b /c:"Everything is Ok" /c:"Scanning" /c:"Creating archive" since you don't need regular expressions (the /r option) here - /b already searches only at the beginning of strings. –  Oliver Feb 23 '13 at 9:43

In case PowerShell is an option or somebody could use it, here's what I did, based on the idea of the findstr answer.

& $sevenZipBin a "$archiveFile" * | where {
    $_ -notmatch "^7-Zip " -and `
    $_ -notmatch "^Scanning$" -and `
    $_ -notmatch "^Creating archive " -and `
    $_ -notmatch "^\s*$" -and `
    $_ -notmatch "^Compressing "
}
if (-not $?)
{
    # Show some error message and possibly exit
}

In normal operation, this leaves only the "Everything is Ok" line. Should anything unusual be printed, it remains visible (except for empty lines as they appear so often in regular output).

This is tested for 7z format output. Other archive formats may produce other messages than "Compressing". Extracting will likely also produce different messages. But you can easily adapt the filter to your needs.

A more complex idea would be to redirect all output to a buffer and only print it in case the command returns an error exit code. This is a method that works with all commands that allow redirecting and provide an accurate error exit code.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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