perl-5.38.0
system LIST
system PROGRAM LIST

Does exactly the same thing as exec, except that a fork is done first and the parent process waits for the child process to exit. Note that argument processing varies depending on the number of arguments. If there is more than one argument in LIST, or if LIST is an array with more than one value, starts the program given by the first element of the list with arguments given by the rest of the list. If there is only one scalar argument, the argument is checked for shell metacharacters, and if there are any, the entire argument is passed to the system's command shell for parsing (this is /bin/sh -c on Unix platforms, but varies on other platforms). If there are no shell metacharacters in the argument, it is split into words and passed directly to execvp, which is more efficient. On Windows, only the system PROGRAM LIST syntax will reliably avoid using the shell; system LIST, even with more than one element, will fall back to the shell if the first spawn fails.

exec とほとんど同じですが、まず fork を行ない、 親プロセスではチャイルドプロセスが終了するのを wait します。 exec の項で述べたように、引数の処理は、引数の数によって異なることに 注意してください。 LIST に複数の引数がある場合、または LIST が複数の要素からなる配列の場合、 リストの最初の要素で与えられるプログラムを、リストの残りの要素を引数として 起動します。 スカラの引数が一つだけの場合、引数はシェルのメタ文字をチェックされ、もし あればパースのために引数全体がシステムコマンドシェル (これは Unix プラットフォームでは /bin/sh -c ですが、他のプラットフォームでは 異なります)に渡されます。 シェルのメタ文字がなかった場合、引数は単語に分解されて直接 execvp に 渡されます; この方がより効率的です。 Windows では、system PROGRAM LIST 構文のみが安定してシェルの使用を 回避します; system LIST は、2 要素以上でも、最初の spawn が失敗すると シェルにフォールバックします。

Perl will attempt to flush all files opened for output before any operation that may do a fork, but this may not be supported on some platforms (see perlport). To be safe, you may need to set $| ($AUTOFLUSH in English) or call the autoflush method of IO::Handle on any open handles.

Perl は書き込み用に開いている全てのファイルに対して fork を行う前にフラッシュしようとしますが、これに対応していない プラットフォームもあります(perlport を参照してください)。 安全のために、$| (English モジュールでは $AUTOFLUSH) をセットするか、全ての開いているハンドルに対して IO::Handleautoflush メソッドを 呼び出す必要があるかもしれません。

The return value is the exit status of the program as returned by the wait call. To get the actual exit value, shift right by eight (see below). 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`" in perlop. Return value of -1 indicates a failure to start the program or an error of the wait(2) system call (inspect $! for the reason).

返り値は、wait が返すプログラムの exit 状態です。 実際の exit 値を得るには 右に 8 ビットシフトしてください(後述)。 exec も参照してください。 これはコマンドからの出力を捕らえるために使うものではありません; そのような用途には、"`STRING`" in perlop に記述されている 逆クォートや qx// を使用してください。 -1 の返り値はプログラムを開始させることに失敗したか、wait(2) システムコールがエラーを出したことを示します (理由は $! を調べてください)。

If you'd like to make system (and many other bits of Perl) die on error, have a look at the autodie pragma.

もし system (及び Perl のその他の多くの部分) でエラー時に die したいなら、autodie プラグマを見てみてください。

Like exec, system allows you to lie to a program about its name if you use the system PROGRAM LIST syntax. Again, see exec.

exec と同様に、system でも system PROGRAM LIST の文法を使うことで、プログラムに対してその名前を 嘘をつくことができます。 再び、exec を参照してください。

Since SIGINT and SIGQUIT are ignored during the execution of system, if you expect your program to terminate on receipt of these signals you will need to arrange to do so yourself based on the return value.

SIGINTSIGQUITsystem の実行中は無視されるので、 これらのシグナルを受信して終了させることを想定したプログラムの場合、 返り値を利用するように変更する必要があります。

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

If you'd like to manually inspect system's failure, you can check all possible failure modes by inspecting $? like this:

system の失敗を手動で検査したいなら、以下のように $? を調べることで、全ての失敗の可能性をチェックできます:

    if ($? == -1) {
        print "failed to execute: $!\n";
    }
    elsif ($? & 127) {
        printf "child died with signal %d, %s coredump\n",
            ($? & 127),  ($? & 128) ? 'with' : 'without';
    }
    else {
        printf "child exited with value %d\n", $? >> 8;
    }

Alternatively, you may inspect the value of ${^CHILD_ERROR_NATIVE} with the W*() calls from the POSIX module.

または、POSIX モジュールの W*() 呼び出しを使って ${^CHILD_ERROR_NATIVE} の値を 調べることもできます。

When system's arguments are executed indirectly by the shell, results and return codes are subject to its quirks. See "`STRING`" in perlop and exec for details.

system の引数がシェルによって間接的に実行された場合、 結果と返り値はシェルの癖によって変更されることがあります。 詳細については "`STRING`" in perlopexec を 参照してください。

Since system does a fork and wait it may affect a SIGCHLD handler. See perlipc for details.

systemforkwait を行うので、 SIGCHLD ハンドラの影響を受けます。 詳しくは perlipc を参照してください。

Portability issues: "system" in perlport.

移植性の問題: "system" in perlport