【问题标题】:How can I open pipes with OO style?如何打开具有 OO 风格的管道?
【发布时间】:2009-02-03 07:49:01
【问题描述】:

我用新的风格重写了我的旧代码,如下所示:

#old style
open(FD,"file");

#new style
$fh = IO::File->new("file","r");

文件没问题,但我不知道如何打开管道。

# read from pipes.
open(PIPE,"some_program |");

# write to pipes.
open(PIPE,"| some_program");

OO Style IO如何处理管道?

添加:
谢谢乔纳森,很好。

# read from pipes.
$pipe = IO::Pipe->new;
$pipe->reader('some_program');
$data = <$pipe>;

# write from pipes.
$pipe = IO::Pipe->new;
$pipe->writer('some_program');
print $pipe "foo,bar,baz";

【问题讨论】:

    标签: perl pipe


    【解决方案1】:

    您应该查看IO::PipeFileHandle

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-18
      • 1970-01-01
      • 2022-01-22
      • 2010-10-06
      • 1970-01-01
      • 2011-10-20
      • 2021-11-05
      • 1970-01-01
      相关资源
      最近更新 更多