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.

mpapec
  • 50,217
  • 8
  • 67
  • 127
  • 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 07 '17 at 06:49
  • Unfortunately I don't have access to the child, and it seems that on windows it can be done by emulating console environment https://stackoverflow.com/a/11549033/223226 – mpapec Oct 07 '17 at 07:06
  • That's basically what `unbuffer` does in unix too. – ikegami Oct 07 '17 at 07:07
  • 1
    Using a module that sets up pty's? – zdim Oct 07 '17 at 07:14
  • Yes, something in that direction. Perhaps https://metacpan.org/pod/Win32::Console – mpapec Oct 07 '17 at 07:15
  • It works with `Expect` (confirmed) -- again, on Linux. Any chance to use Cygwin? – zdim Oct 07 '17 at 07:34
  • Tnx for the info but can't switch to cygwin. – mpapec Oct 07 '17 at 08:05

0 Answers0