#!/usr/bin/perl use strict; use warnings; use IPC::Open3; use IO::Select; my @cmd = qw'echo bar'; # writing to 'echo' fails #my @cmd = qw'cat'; # ... while 'cat' works open3(my $wh, my $rh, undef, @cmd); # tiny delay, so the command gets enough time to close STDIN # (prevent potential race condition, in this demo script) select undef,undef,undef, 0.1; my $msg = "foo"; #----- print $wh "$msg\n"; close $wh; #----- my $data = ""; if (IO::Select->new($rh)->can_read()) { print "reading from $rh ('@cmd |')\n"; while (sysread($rh, my $buffer, 1000)) { $data .= $buffer; } } print "data: $data\n";