http://www.perlmonks.org?node_id=970244

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

I want to create a simple IO object that represents a pipe opened to another program to that I can periodically write to another program's STDIN as my app runs. I want it to be bullet-proof (in that it catches all errors) and cross-platform. The best options I can find are:

open

sub io_read { local $SIG{__WARN__} = sub { }; # Silence warning. open my $pipe, '|-', @_ or die "Cannot exec $_[0]: $!\n"; return $pipe; }

Advantages:

Disadvantages

IO::Pipe

sub io_read { IO::Pipe->reader(@_); }

Advantages:

Disadvantages

IPC::Run

There is no interface for writing to a file handle in IPC::Run, only appending to a scalar. This seems…weird.

IPC::Run3

No file handle interface here, either. I could use a code reference, which would be called repeatedly to spool to the child, but looking at the source code, it appears that it actually writes to a temporary file, and then opens it and spools its contents to the pipe'd command's STDIN. Wha?

IPC::Cmd

Still no file handle interface.


What am I missing here? It seems as if this should be a solved problem, and I'm kind of stunned that it's not. IO::Pipe comes closest to what I want, but the lack of $SIG{PIPE} error handling and the lack of support for Windows is distressing. Where is the piping module that will JDWIM?