perl-5.38.0
    qx/STRING/

    A string which is (possibly) interpolated and then executed as a system command, via /bin/sh or its equivalent if required. Shell wildcards, pipes, and redirections will be honored. Similarly to system, if the string contains no shell metacharacters then it will executed directly. The collected standard output of the command is returned; standard error is unaffected. In scalar context, it comes back as a single (potentially multi-line) string, or undef if the shell (or command) could not be started. In list context, returns a list of lines (however you've defined lines with $/ or $INPUT_RECORD_SEPARATOR), or an empty list if the shell (or command) could not be started.

    展開され、必要なら /bin/sh またはそれと等価なものでシステムの コマンドとして実行される(であろう)文字列です。 シェルのワイルドカード、パイプ、リダイレクトが有効です。 system と同様、文字列にシェルメタ文字が含まれていないときは、 直接実行されます。 そのコマンドの、標準出力を集めたものが返されます; 標準エラーは影響を 与えません。 スカラコンテキストでは、(複数行を含むかもしれない) 1 つの文字列が戻ってきます; シェル (またはコマンド) が開始できなかったときは undef を返します。 リストコンテキストでは、($/ もしくは $INPUT_RECORD_SEPARATOR を どのように設定していても) 行のリストを返します; シェル (またはコマンド) が開始できなかったときは 空リストを返します。

    Because backticks do not affect standard error, use shell file descriptor syntax (assuming the shell supports this) if you care to address this. To capture a command's STDERR and STDOUT together:

    バッククォートは標準エラーには影響を与えないので、標準エラーを 使いたい場合は(シェルが対応しているものとして)シェルのファイル記述子の 文法を使ってください。 コマンドの STDERR と STDOUT を共に取得したい場合は:

        $output = `cmd 2>&1`;

    To capture a command's STDOUT but discard its STDERR:

    コマンドの STDOUT は取得するが STDERR は捨てる場合は:

        $output = `cmd 2>/dev/null`;

    To capture a command's STDERR but discard its STDOUT (ordering is important here):

    コマンドの STDERR は取得するが STDOUT は捨てる場合は (ここでは順序が重要です):

        $output = `cmd 2>&1 1>/dev/null`;

    To exchange a command's STDOUT and STDERR in order to capture the STDERR but leave its STDOUT to come out the old STDERR:

    STDERR を取得するが、STDOUT は古い STDERR のために残しておくために STDOUT と STDERR を交換するには:

        $output = `cmd 3>&1 1>&2 2>&3 3>&-`;

    To read both a command's STDOUT and its STDERR separately, it's easiest to redirect them separately to files, and then read from those files when the program is done:

    コマンドの STDOUT と STDERR の両方を別々に読み込みたい場合、 一番簡単な方法は別々のファイルにリダイレクトし、 プログラムが終了してからそのファイルを読むことです:

        system("program args 1>program.stdout 2>program.stderr");

    The STDIN filehandle used by the command is inherited from Perl's STDIN. For example:

    コマンドによって使われる STDIN ファイルハンドルは Perl の STDIN を 継承します。 例えば:

        open(SPLAT, "stuff")   || die "can't open stuff: $!";
        open(STDIN, "<&SPLAT") || die "can't dupe SPLAT: $!";
        print STDOUT `sort`;

    will print the sorted contents of the file named "stuff".

    "stuff" という名前のファイルの内容をソートして表示します。

    Using single-quote as a delimiter protects the command from Perl's double-quote interpolation, passing it on to the shell instead:

    シングルクォートをデリミタとして使うと Perl のダブルクォート展開から 保護され、そのままシェルに渡されます:

        $perl_info  = qx(ps $$);            # that's Perl's $$
        $shell_info = qx'ps $$';            # that's the new shell's $$

    How that string gets evaluated is entirely subject to the command interpreter on your system. On most platforms, you will have to protect shell metacharacters if you want them treated literally. This is in practice difficult to do, as it's unclear how to escape which characters. See perlsec for a clean and safe example of a manual fork() and exec() to emulate backticks safely.

    この文字列がどのように評価されるかは完全にシステムのコマンドインタプリタに 依存します。 ほとんどのプラットフォームでは、シェルのメタ文字をリテラルに 扱ってほしい場合はそれを守る必要があります。 文字をエスケープする方法が明確ではないので、これは理論的には難しいことです。 逆クォートを安全にエミュレートするために手動で fork()exec() を 行うためのきれいで安全な例については perlsec を参照してください。

    On some platforms (notably DOS-like ones), the shell may not be capable of dealing with multiline commands, so putting newlines in the string may not get you what you want. You may be able to evaluate multiple commands in a single line by separating them with the command separator character, if your shell supports that (for example, ; on many Unix shells and & on the Windows NT cmd shell).

    (特に DOS 風の)プラットフォームには、シェルが複数行のコマンドを扱うことが できないものがあるので、文字列に改行を入れるとあなたの望まない結果に なる場合があります。 シェルが対応していれば、コマンド分割文字で分割することで 1 行に複数のコマンドを入れて解釈させることができます (この文字は、多くの Unix シェルでは ;、Windows NT cmd シェルでは & です)。

    Perl will attempt to flush all files opened for output before starting the child process, 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 は子プロセスの実行前に書き込み用に開いている全ての ファイルをフラッシュしようとしますが、これに対応していない プラットフォームもあります(perlport を参照してください)。 安全のためには、$| (English モジュールでは $AUTOFLUSH)を セットするか、開いている全てのハンドルに対して IO::Handleautoflush() メソッドを呼び出す必要があります。

    Beware that some command shells may place restrictions on the length of the command line. You must ensure your strings don't exceed this limit after any necessary interpolations. See the platform-specific release notes for more details about your particular environment.

    コマンド行の長さに制限があるコマンドシェルがあることに注意してください。 全ての必要な変換が行われた後、コマンド文字列がこの制限を越えないことを 保障する必要があります。 特定の環境に関するさらなる詳細についてはプラットフォーム固有の リリースノートを参照してください。

    Using this operator can lead to programs that are difficult to port, because the shell commands called vary between systems, and may in fact not be present at all. As one example, the type command under the POSIX shell is very different from the type command under DOS. That doesn't mean you should go out of your way to avoid backticks when they're the right way to get something done. Perl was made to be a glue language, and one of the things it glues together is commands. Just understand what you're getting yourself into.

    この演算子を使うと、プログラムの移殖が困難になります; 呼び出されるシェル コマンドはシステムによって異なり、実際全く存在しないこともあるからです。 一つの例としては、POSIX シェルの type コマンドは DOS の type コマンドと 大きく異なっています。 これは、何かを為すために正しい方法として逆クォートを使うことを 避けるべきであることを意味しません。 Perl は接着剤のような言語として作られ、接着されるべきものの一つは コマンドです。 単にあなたが何をしようとしているかを理解しておいてください。

    Like system, backticks put the child process exit code in $?. If you'd like to manually inspect 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;
        }

    Use the open pragma to control the I/O layers used when reading the output of the command, for example:

    コマンドの出力を読み込むのに使われる I/O 層を制御するには open を使います; 例えば:

      use open IN => ":encoding(UTF-8)";
      my $x = `cmd-producing-utf-8`;

    qx// can also be called like a function with "readpipe" in perlfunc.

    qx// はまた、"readpipe" in perlfunc のような関数から呼び出されます。

    See "I/O Operators" for more discussion.

    さらなる議論については "I/O Operators" を参照して下さい。