3

I would like to get child output as soon as it gets printed, and not all at once when child finishes, ie.

use strict;
use warnings;

# this is only example of buffered child output
open (my $fh, "-|", "perl", "-E", "sleep(1),say for 1..10") // die $!;

# all lines are buffered
while (my $line = <$fh>) {
    print $line;
}

On linux it can be achieved with unbuffer.

7
  • I find that adding \$ = 1 to the child works ... on Linux (can't test on Windows right now). Don't know whether it suits the purpose? It requires access to the child program.
    – zdim
    Oct 7, 2017 at 6:49
  • Unfortunately I don't have access to the child, and it seems that on windows it can be done by emulating console environment stackoverflow.com/a/11549033/223226
    – mpapec
    Oct 7, 2017 at 7:06
  • That's basically what unbuffer does in unix too.
    – ikegami
    Oct 7, 2017 at 7:07
  • 1
    Using a module that sets up pty's?
    – zdim
    Oct 7, 2017 at 7:14
  • Yes, something in that direction. Perhaps metacpan.org/pod/Win32::Console
    – mpapec
    Oct 7, 2017 at 7:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.