From e8da6232d1bee97e72af95f5f67c6df756667038 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 6 Apr 2020 18:02:45 +0200 Subject: Fix: Do not write data if output is pipe Signed-off-by: Matthias Beyer --- bin/core/imag-grep/src/lib.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/bin/core/imag-grep/src/lib.rs b/bin/core/imag-grep/src/lib.rs index 76ea5bca..53101a3f 100644 --- a/bin/core/imag-grep/src/lib.rs +++ b/bin/core/imag-grep/src/lib.rs @@ -120,12 +120,16 @@ impl ImagApplication for ImagGrep { .len(); if opts.count { - writeln!(rt.stdout(), "{}", count)?; + if !rt.output_is_pipe() || rt.output_data_pipe() { + writeln!(rt.stdout(), "{}", count)?; + } } else if !opts.files_with_matches { - writeln!(rt.stdout(), "Processed {} files, {} matches, {} nonmatches", - overall_count, - count, - overall_count - count)?; + if !rt.output_is_pipe() || rt.output_data_pipe() { + writeln!(rt.stdout(), "Processed {} files, {} matches, {} nonmatches", + overall_count, + count, + overall_count - count)?; + } } Ok(()) @@ -150,6 +154,11 @@ impl ImagApplication for ImagGrep { } fn show(rt: &Runtime, e: &Entry, re: &Regex, opts: &Options, count: &mut usize) -> Result<()> { + if rt.output_is_pipe() && !rt.output_data_pipe() { + // leave if output is a pipe and behaviour is not overridden + return Ok(()) + } + if opts.files_with_matches { writeln!(rt.stdout(), "{}", e.get_location())?; } else if opts.count { -- cgit v1.2.3