EvanCarroll has asked for the wisdom of the Perl Monks concerning the following question:

Is there a reason why IPC::Open2 doesn't work with fifos, or am I doing something wrong.

These two examples must be run in different ttys, or you must background the echo to foobar, because it will wait for the output to be read before echo detaches.
mkfifo foobar; echo "this is a test of the emergency fifo system" > foobar;
use IPC::Open2; open(my $fifo, "<", "foobar") or die $!; my $o; open(my $fh, ">", \$o) or die $!; open2($fh, $fifo, "/bin/echo") or die $!; print $o;


Evan Carroll
I hack for the ladies.
www.EvanCarroll.com

Replies are listed 'Best First'.
Re: My fifo wtf.
by ikegami (Patriarch) on Dec 18, 2008 at 03:12 UTC
    You want cat (which echos its STDIN) for the child process, not echo (which echos its args).

    Update: Added "for the child process" as per reply.

      You should have specified that it is the second echo that should be replaced by cat.
Re: My fifo wtf.
by ikegami (Patriarch) on Dec 18, 2008 at 03:16 UTC

    Also, open \$var doesn't create a system file handle, just a Perl handle. It can't become the child's STDOUT.

      So how do you capture STDOUT from the child into perl?


      Evan Carroll
      I hack for the ladies.
      www.EvanCarroll.com
        open(my $from_child, '-|', "cat < foobar") or die $!; <$from_child>
        open2(my $from_child, $fifo, "cat") or die $!; <$from_child>