use strict; use warnings; use IO::Select; my $cmd = '"cat /etc/passwd"'; my $login = 'usr@host'; my $pkey = "$ENV{HOME}/.ssh/privateKey"; my @shell = ( '/usr/bin/ksh' => ( -c => "$cmd", )); my @sshcmd = ('/usr/bin/ssh' => ( -t => (), -i => $pkey, -o => 'StrictHostKeyChecking no', $login, @shell, )); if(my $child = open (IFILE, '-|')) { print STDERR "I'm the parent\n"; print STDERR "Child pid=$child\n"; }else{ select(STDIN); $|++; select(STDOUT); $|++; select(STDERR); $|++; print STDERR "I am the child\n"; print "LINE 1...\n"; print "LINE 2...\n"; print "LINE 3...\n"; print "LINE 4...\n"; my $ret; $ret = system('echo hi'); print STDERR "CHILD 1: ret=$ret\n"; $ret = system(@sshcmd); print STDERR "CHILD 2: ret=$ret\n"; print "LINE 5...\n"; print "LINE 6...\n"; print "LINE 7...\n"; print "LINE 8...\n"; } my $select = IO::Select->new(); $select->add(\*IFILE); my @ready; while ( @ready = $select->can_read(5) ) { foreach my $fh (@ready) { my $line = <$fh>; print STDERR "line=$line"; if(eof($fh)) { $select->remove($fh); close($fh) || warn "Close problem on fh: $fh"; } } } close(IFILE);