@@ -950,12 +950,13 @@ fn wc(inputs: &Inputs, settings: &Settings) -> UResult<()> {
950950 }
951951 } ;
952952
953- let word_count = match word_count_from_input ( & input, settings) {
954- CountResult :: Success ( word_count) => word_count,
955- CountResult :: Interrupted ( word_count, err) => {
956- show ! ( err. map_err_context( || input. path_display( ) ) ) ;
957- word_count
958- }
953+ // Store any I/O error from reading to print AFTER stats (matches GNU wc behavior)
954+ let ( word_count, deferred_error) = match word_count_from_input ( & input, settings) {
955+ CountResult :: Success ( word_count) => ( word_count, None ) ,
956+ CountResult :: Interrupted ( word_count, err) => (
957+ word_count,
958+ Some ( err. map_err_context ( || input. path_display ( ) ) ) ,
959+ ) ,
959960 CountResult :: Failure ( err) => {
960961 show ! ( err. map_err_context( || input. path_display( ) ) ) ;
961962 continue ;
@@ -970,6 +971,11 @@ fn wc(inputs: &Inputs, settings: &Settings) -> UResult<()> {
970971 show ! ( err. map_err_context( || translate!( "wc-error-failed-to-print-result" , "title" => title. to_string_lossy( ) ) ) ) ;
971972 }
972973 }
974+ // Print deferred error after stats to match GNU wc output order
975+ if let Some ( err) = deferred_error {
976+ let _ = io:: stdout ( ) . flush ( ) ;
977+ show ! ( err) ;
978+ }
973979 }
974980
975981 if settings. total_when . is_total_row_visible ( num_inputs) {
0 commit comments