icon Top 9 categories map      RocketAware > Perl >

system LIST

Tips: Browse or Search all pages for efficient awareness of Perl functions, operators, and FAQs.


Search Perl pages


By activity
Professions, Sciences, Humanities, Business, ...

User Interface
Text-based, GUI, Audio, Video, Keyboards, Mouse, Images,...

Text Strings
Conversions, tests, processing, manipulation,...

Integer, Floating point, Matrix, Statistics, Boolean, ...

Algorithms, Memory, Process control, Debugging, ...

Stored Data
Data storage, Integrity, Encryption, Compression, ...

Networks, protocols, Interprocess, Remote, Client Server, ...

Hard World
Timing, Calendar and Clock, Audio, Video, Printer, Controls...

File System
Management, Filtering, File & Directory access, Viewers, ...

system LIST
Does exactly the same thing as ``exec LIST'' except that a fork is done first, and the parent process waits for the child process to complete. Note that argument processing varies depending on the number of arguments. The return value is the exit status of the program as returned by the wait() call. To get the actual exit value divide by 256. See also exec. This is NOT what you want to use to capture the output from a command, for that you should use merely backticks or qx//, as described in `STRING`.

Because system() and backticks block SIGINT and SIGQUIT, killing the program they're running doesn't actually interrupt your program.

    @args = ("command", "arg1", "arg2");
    system(@args) == 0
         or die "system @args failed: $?"

Here's a more elaborate example of analysing the return value from system() on a Unix system to check for all possibilities, including for signals and core dumps.

    $rc = 0xffff & system @args;
    printf "system(%s) returned %#04x: ", "@args", $rc;
    if ($rc == 0) {
        print "ran with normal exit\n";
    elsif ($rc == 0xff00) {
        print "command failed: $!\n";
    elsif ($rc > 0x80) {
        $rc >>= 8;
        print "ran with non-zero exit status $rc\n";
    else {
        print "ran with ";
        if ($rc &   0x80) {
            $rc &= ~0x80;
            print "core dump from ";
        print "signal $rc\n"
    $ok = ($rc != 0);

When the arguments get executed via the system shell, results will be subject to its quirks and capabilities. See `STRING` for details.

Source: Perl builtin functions
Copyright: Larry Wall, et al.


(Corrections, notes, and links courtesy of RocketAware.com)

[Overview Topics]

Up to: Process Creation and Control

Rapid-Links: Search | About | Comments | Submit Path: RocketAware > Perl > perlfunc/system.htm
RocketAware.com is a service of Mib Software
Copyright 2000, Forrest J. Cavalier III. All Rights Reserved.
We welcome submissions and comments