Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 5075c87c46
Fetching contributors…

Cannot retrieve contributors at this time

file 36 lines (21 sloc) 1.118 kb

There are three ways to call external programs.

    my $rc = system("/bin/cp $file1 $file2"); # returns exit status values
    die "system() failed with status $rc" unless $rc == 0;

If possible, pass your arguments as a list, rather than a single string.

    my $rc = system("/bin/cp", $file1, $file2 );

This makes sure that nothing goes wrong in the shell if $file1 or $file2 have spaces or other special characters.

The output from system() is not captured.

XXX Discuss lower 8-bits of return code.

XXX Discuss running through a pipe

When you want the output, use one of these.

    my $output = `myprogram foo bar`.

You'll need to check the error code in $!.

If you're using backticks or qx(), prefer IPC::Open2 or IPC::Open3 instead, since they'll give you the same argument control and allow you to capture the output as well.

IPC::Open3 is the only way to capture STDERR in Perl without using shell commands.

Something went wrong with that request. Please try again.