in reply to Re^6: Need sleep walking help
in thread Need sleep walking help

Hi Marshall,

Program 1's error messages come out right way while stdout messages come later because the stdout's filehandle's output buffer is not ready to be "flushed", "printed".

Sorry, but that's not quite correct either. If run from the terminal, your Program 1's STDOUT will be line-buffered and will flush its STDOUT on every newline, but the order in which STDOUT and STDERR output is intermixed on the terminal is AFAIK not well-defined. On my machine, the output of both programs looks the same when run from the terminal.

See also my post here.

Regards,
-- Hauke D

Replies are listed 'Best First'.
Re^8: Need sleep walking help
by Marshall (Canon) on Feb 02, 2017 at 09:14 UTC
    Ok, fair enough. There are some fine details here, one of which is whether the std output is going to a terminal or not? I did a copy and paste from my dev environment which is not exactly the same as running from the command line directly.

    My demo is not "bullet proof", but I think it gives the idea of what can happen.

    Thanks for your good points.

      Hi Marshall,

      I did a copy and paste from my dev environment which is not exactly the same as running from the command line directly.

      Sure, that's a possibility. Even something as seemingly simple as perl foo.pl | grep bar or even perl foo.pl | cat on the terminal will cause Perl to turn off line buffered mode on STDOUT and cause the need for $|++ if you want "live" output.

      Regards,
      -- Hauke D

        Yes, that is what is happening. I very seldom run Perl directly from the command line without redirecting output to a file.

        I do most of my work on Windows and for reasons that mystify me, writing to the command window terminal is super duper slow. Many of my programs are written as Unix style filters and often they will become I/O limited to the STDOUT terminal speed without STDOUT and/or STDERR re-direction to a file. Other O/S'es that I've worked on just fly 5K lines to the terminal in a blur - but not Windows. Windows must have some sort of max speed throttle when writing to the command window. If anybody knows to increase that speed, I'd like to know!

        I use Textpad for Perl dev on Windows. It captures STDERR and STDOUT to a new edit window when I "push the Perl "go" button". I come across the need for $|=1; all the time and I've gotten used to that quirk so much that I don't think about it much.

        I think this completely explains my results.