Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you don't want the contents of STDERR, then the capture() command from <a href="http://search.cpan.org/perldoc?IPC::System::Simple" rel="noreferrer">IPC::System::Simple</a> module is almost exactly what you're after:</p> <pre><code> use IPC::System::Simple qw(capture system $EXITVAL); my $output = capture($cmd, @args); my $exit_value = $EXITVAL; </code></pre> <p>You can use capture() with a single argument to invoke the shell, or multiple arguments to reliably avoid the shell. There's also capturex() which never calls the shell, even with a single argument.</p> <p>Unlike Perl's built-in system and backticks commands, IPC::System::Simple returns the full 32-bit exit value under Windows. It also throws a detailed exception if the command can't be started, dies to a signal, or returns an unexpected exit value. This means for many programs, rather than checking the exit values yourself, you can rely upon IPC::System::Simple to do the hard work for you:</p> <pre><code> use IPC::System::Simple qw(system capture $EXIT_ANY); system( [0,1], "frobincate", @files); # Must return exitval 0 or 1 my @lines = capture($EXIT_ANY, "baznicate", @files); # Any exitval is OK. foreach my $record (@lines) { system( [0, 32], "barnicate", $record); # Must return exitval 0 or 32 } </code></pre> <p>IPC::System::Simple is pure Perl, has no dependencies, and works on both Unix and Windows systems. Unfortunately, it doesn't provide a way of capturing STDERR, so it may not be suitable for all your needs.</p> <p><a href="http://search.cpan.org/perldoc?IPC::Run3" rel="noreferrer">IPC::Run3</a> provides a clean and easy interface into re-plumbing all three common filehandles, but unfortunately it doesn't check to see if the command was successful, so you'll need to inspect $? manually, which is not at all fun. Providing a public interface for inspecting $? is something which is on my <a href="http://rt.cpan.org/Public/Bug/Display.html?id=26519" rel="noreferrer">to-do list</a> for IPC::System::Simple, since inspecting $? in a cross-platform fashion is not a task I'd wish on anyone.</p> <p>There are other modules in the <a href="http://search.cpan.org/search?query=IPC%3A%3A&amp;mode=all" rel="noreferrer">IPC::</a> namespace that may also provide you with assistance. YMMV.</p> <p>All the best,</p> <p>Paul</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload