in reply to Challenge: Capturing stdout from a function call.
#!/usr/bin/perl use strict; use warnings; sub function { print "Hello, world\n"; } my $kid; my $pid = open ($kid, "-|"); die "Failed to fork: $!" unless defined $pid; unless ($pid) { # Child. function; exit; } undef $/; my $scalar = <$kid>; print "Got: $scalar"; __END__ Got: Hello, world
See also the perlipc manual page.
|
|---|