in reply to [UPDATED] How to autoflush streams (i.e. open3 calls)

You have set autoflush for STDOUT but not for STDERR, so, just do it:
select(STDERR); $| = 1; select(STDOUT); $| = 1;

Replies are listed 'Best First'.
Re^2: How to autoflush streams (i.e. open3 calls)
by rapide (Beadle) on Jan 29, 2009 at 11:24 UTC
    are not STDERR automatically flushed?
      oops, yes you are right!

      The actual problem probably is that when the parent goes to read, the children has already finished and all the data is awaiting on the pipes buffers. The parent reads then first all the data from child STDOUT and then the data from child STDERR.

      AFAIK there is no way to synchronize child writes with parent reads.

      If you really need to know the order in with data is printed, use the same pipe for STDOUT and STDERR and preppend every line with a channel identifier so you can demultiplex it on the parent process.

Re^2: How to autoflush streams (i.e. open3 calls)
by Anonymous Monk on Jan 29, 2009 at 11:25 UTC
    perl -MIO::Handle -e ' STDOUT->autoflush(1); print 1; sleep 1; print 2 + '
      But STDERR seems to be autoflushed by default:
      perl -MIO::Handle -e ' print 1; print STDERR 33; sleep 1; print 2';