but which is recommended?

Well, it depends...

IPC::Open3 is an old module with an ugly interface and limited functionality. On the other hand you can rely on it being available mostly everywhere as it is distributed with Perl.

IPC::Run is a feature rich module and quite popular too. I find its API too complex, but that is probably the prize you pay for being feature rich!.

There is another alternative if you don't need your scripts to run on any OS other than Linux or Unix: to use the raw POSIX calls (fork, exec, dup2, etc.). In other words, doing it a-la 'C'.

In your particular case, where you are not sending any data to the child process, there is an even simpler solution: to use a single pipe. Perl provides native support for that via the open built-in:

my $pid = open my $rdr, "$cmd |" or die "unable to run external comman +d: $!"; while (<$rdr>) { ... } close $rdr or die "reading from $rdr failed: $!";

Or even better, in order to avoid the shell (specially if it is the today infamous bash!), using the multi-argument open invocation:

my $pid = open my $rdr, '-|', $cmd, @args or die "unable to run extern +al command: $!"; while (<$rdr>) { ... } close $rdr or die "reading from $rdr failed: $!";

In reply to Re^5: waitpid stalling on one particular file by salva
in thread waitpid stalling on one particular file by seaver

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.