【问题标题】:In Perl, how to clone output to stdout and a log file in real time在 Perl 中,如何将输出实时克隆到标准输出和日志文件
【发布时间】:2015-07-09 06:55:35
【问题描述】:

我想同时将输出克隆到控制台和日志文件。这是我的代码 sn-p:

open STDOUT, ">>", "temp.txt" or die "";
system("echo This is a sample output..........");

但是,这里我只在temp.txt 中获得输出,而不是在控制台上。 你能提出一个解决方案吗?我正在使用 Windows。

【问题讨论】:

    标签: perl windows-console


    【解决方案1】:

    它将输出到STDOUTtemp.txt

    use Capture::Tiny::Extended 'tee';
    
    tee(
      sub { 
        system("echo This is a sample output..........");
      },
      { stdout => "temp.txt" }
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-31
      • 2018-01-09
      • 2021-07-03
      • 1970-01-01
      • 2011-09-18
      • 2017-04-13
      • 1970-01-01
      相关资源
      最近更新 更多