Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

system

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).

Synopsis

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

See Also

exec, fork, waitpid, backticks, $?