my $CMD = 'cat'; use IO::Handle; use IPC::Open3 qw( open3 ); use strict; my $pid = fork(); if ( !defined($pid) ) { die( "$$: Fork failed: $!\n" ); } # parent if ( $pid ) { print( "$$ FORKED $pid\n" ); } # child else { my( $pw, $pr, $pe, $pipe ); foreach $pipe ( $pw, $pr, $pe ) { $pipe = new IO::Handle; } my $pipe_pid = open3( $pw, $pr, $pe, $CMD ) or die( "$$: failed to handle to $CMD: $!\n" ); print( "$$:\tpipe pid = $pipe_pid\n"); $pw->print( "hostinfo\n" ); $pw->print( "quit\n" ); print( "$$: out: ", $pr->getline(), "\n" ); exit(0); } waitpid( $pid, 0 ); print( "$$ caught $pid: $?\n" ); print( "PARENT $$ exiting\n" );