How can I send Perl output to a both STDOUT and a variable?

前端 未结 8 1033
耶瑟儿~
耶瑟儿~ 2020-12-03 22:20

I would like to send the output from a command to both STDOUT and to a variable. I want to combine:

my $var = `some command` ;   
system( \'some command\' )          


        
8条回答
  •  隐瞒了意图╮
    2020-12-03 22:36

    You want Capture::Tiny

    use Capture::Tiny 'tee';
    my $output = tee { system( "some command" ) };
    

    I wrote it to replace Tee and about 20 other modules that do some sort of capturing but are flawed in one way or another.

    -- xdg (aka dagolden)

提交回复
热议问题