All pastes #176088 Raw Edit

Miscellany

public text v1 · immutable
·published 2006-09-19 11:44 UTC
rendered paste body
    sub pipe_from_fork ($) {
        my $rv;
        my $parent = shift;
        pipe $parent, my $child or die;
        my $pid = fork();
        die "fork() failed: $!" unless defined $pid;
        if ($pid) {
            close $child;
            $rv=$parent;
        }
        else {
            close $parent;
            open(STDOUT, ">&=" . fileno($child)) or die;
            $rv=$child;
        }
        ($pid,$rv);
    }