6

Perl で実行するシステム コマンドの出力用のファイルハンドル/ハンドルはありますか?

4

2 に答える 2

12

の 3 引数形式を使用して、スクリプトと他のコマンドの間にパイプを確立する例を次に示しますopen

open(my $incoming_pipe, '-|', 'ls -l')             or die $!;
open(my $outgoing_pipe, '|-', "grep -v '[02468]'") or die $!;

my @listing = <$incoming_pipe>;          # Lines from output of ls -l
print $outgoing_pipe "$_\n" for 1 .. 50; # 1 3 5 7 9 11 ...
于 2010-07-14T03:01:28.197 に答える
1

はい、次のようなパイプを使用できます。

open(my $pipe, "ls|") or die "Cannot open process: $!";
while (<$pipe>) {
    print;
}

open詳細およびperlipcパイプ操作の完全な説明については、ドキュメントを参照してください。

于 2010-07-14T00:38:18.710 に答える