Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6323555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:32:27+00:00 2026-05-24T16:32:27+00:00

Given a third-party program, how would one simultaneously: write stdout to z.stdout write stderr

  • 0

Given a third-party program, how would one simultaneously:

  1. write stdout to z.stdout
  2. write stderr to z.stderr
  3. pass exit codes appropriately
  4. write both in correct interleaved order to stdout

Here’s the test program (delayed_interleaved_stdout_stderr.pl) I’ve been using:

#!/usr/bin/env perl

use strict;
use warnings;

# fixme: debug, uncomment to force stdout flushing
# use English '-no_match_vars';
# $OUTPUT_AUTOFLUSH = 1;

# use sleeps to simulate delays and test buffering
use Time::HiRes 'sleep';

foreach my $num ( 0..9 ) {
  if ( 0 == $num % 2 ) {
    print STDOUT $num, ":stdout\n";
  }
  else {
    print STDERR $num, ":stderr\n";
  }
  sleep 0.25;
}

So far I’ve been able to do 1,2,3 with:

( set -o pipefail; \
  ( set -o pipefail; delayed_interleaved_stdout_stderr.pl \
    | tee z.stdout; exit $? \
  ) 3>&1 1>&2 2>&3 | tee z.stderr; exit $? \
) 3>&1 1>&2 2>&3

Thanks to a related answer by lhunath and a friend, I simplified it to:

delayed_interleaved_stdout_stderr.pl > >(tee z.stdout) 2> >(tee z.stderr >&2)

However, I haven’t been able to get correct interleaved order. stderr prints immediately and the (presumably buffered) stdout all prints at the end.

1:stderr
3:stderr
5:stderr
7:stderr
9:stderr
0:stdout
2:stdout
4:stdout
6:stdout
8:stdout

Running delayed_interleaved_stdout_stderr.pl by itself displays in the proper 0-9 order. Forcing stdout to flush works appropriately (see commented fixme section), but I won’t be able to modify the real files.

Maybe I’m missing something basic and I’m beginning to wonder if this is possible at all 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:32:28+00:00Added an answer on May 24, 2026 at 4:32 pm

    I confirmed I can enforce stdout flushing for the third-party programs. In light of this, I’m going with

    delayed_interleaved_stdout_stderr.pl > >(tee z.stdout) 2> >(tee z.stderr >&2)
    

    Thanks for all help!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a third-party GUI program that I'm wrapping with a Python class (using
Given paths like this: /data/mirrors/third-party/centos/5/projectA/x86_64 /data/mirrors/third-party/centos/5/projectA/i386 /data/mirrors/third-party/centos/5/projectA/noarch /data/mirrors/third-party/centos/4/projectB/x86_64 /data/mirrors/third-party/centos/4/projectB/i386 /data/mirrors/third-party/centos/4/projectB/noarch /data/mirrors/third-party/centos/4/projectC/x86_64 /data/mirrors/third-party/centos/4/projectC/i386 /data/mirrors/third-party/centos/4/projectC/noarch How
My Gae application retrieves JSON data from a third party site; given an ID
I was reviewing some code given to us by a third-party outsourcing firm and
I need to automate a third party program, and the only course of action
a brain dead third party program I'm forced to use determines how to treat
I have a third party java program called kgsgtp.jar which need to communicate with
Given a third party system that streams XML to me via TCP. The TOTAL
Given an absolute or relative path (in a Unix-like system), I would like to
I have a program that does batch processing on some drawings. One of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.