diff --git a/src/find/matchers/mod.rs b/src/find/matchers/mod.rs index ca2ed15e..b22783d2 100644 --- a/src/find/matchers/mod.rs +++ b/src/find/matchers/mod.rs @@ -65,7 +65,7 @@ use ls::Ls; use std::{ error::Error, fs::{File, Metadata}, - io::Read, + io::{stderr, Read, Write}, path::Path, str::FromStr, time::SystemTime, @@ -1002,7 +1002,7 @@ fn parse_files0_args(config: &mut Config) -> Result<(), Box> { .collect(); // empty starting point checker if string_segments.iter().any(|s| s.is_empty()) { - eprintln!("find: invalid zero-length file name"); + let _ = writeln!(stderr(), "find: invalid zero-length file name"); // remove the empty ones so as to avoid file not found error string_segments.retain(|s| !s.is_empty()); } diff --git a/src/find/matchers/printf.rs b/src/find/matchers/printf.rs index 826f6b25..8d864fda 100644 --- a/src/find/matchers/printf.rs +++ b/src/find/matchers/printf.rs @@ -8,7 +8,10 @@ use std::error::Error; use std::fs::{self, File}; use std::path::Path; use std::time::SystemTime; -use std::{borrow::Cow, io::Write}; +use std::{ + borrow::Cow, + io::{stderr, Write}, +}; use chrono::{format::StrftimeItems, DateTime, Local}; @@ -608,7 +611,8 @@ impl Printf { } } Err(e) => { - eprintln!( + let _ = writeln!( + stderr(), "Error processing '{}': {}", file_info.path().to_string_lossy(), e diff --git a/src/xargs/mod.rs b/src/xargs/mod.rs index f1a14cc4..9a54bad7 100644 --- a/src/xargs/mod.rs +++ b/src/xargs/mod.rs @@ -10,7 +10,7 @@ use std::{ ffi::{OsStr, OsString}, fmt::Display, fs, - io::{self, BufRead, BufReader, Read}, + io::{self, stderr, BufRead, BufReader, Read, Write}, process::{Command, Stdio}, }; @@ -439,7 +439,7 @@ impl CommandBuilder<'_> { } if self.options.verbose { - eprintln!("{command:?}"); + let _ = writeln!(stderr(), "{command:?}"); } match &self.options.action { @@ -827,7 +827,7 @@ fn normalize_options(options: Options, matches: &clap::ArgMatches) -> Options { (options.max_args, options.max_lines, None) } _ => { - eprintln!( + let _ = writeln!(stderr(), "WARNING: -L, -n and -I/-i are mutually exclusive, but more than one were given; \ only the last option will be used" ); @@ -1154,7 +1154,7 @@ pub fn xargs_main(args: &[&str]) -> i32 { Ok(CommandResult::Success) => 0, Ok(CommandResult::Failure) => 123, Err(e) => { - eprintln!("Error: {e}"); + let _ = writeln!(stderr(), "Error: {e}"); if let XargsError::CommandExecution(cx) = e { match cx { CommandExecutionError::UrgentlyFailed => 124,