system#

Synopsis#

my $status = system("ls -la");
my $status = system("program", "arg1", "arg2");
system("echo hello") == 0 or die "system failed: $?";

Description#

Executes an external command and waits for it to complete.

In the single-argument form, the command string is passed to /bin/sh -c for shell interpretation (pipes, redirects, etc.). In the multi-argument form (list form), the program is executed directly via execvp without a shell, avoiding shell metacharacter interpretation.

Returns the full wait status (same encoding as $?):

  • 0 on success (exit code 0)

  • $? >> 8 extracts the exit code

  • Lower 8 bits contain signal information

  • -1 on failure to execute

The child process inherits Perl’s %ENV (not the OS environment).

See also#

exec, fork, waitpid, backticks, $?