如何将Perl输出发送到STDOUT和变量? [英] How can I send Perl output to a both STDOUT and a variable?
本文介绍了如何将Perl输出发送到STDOUT和变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将命令的输出发送到STDOUT和变量.我想结合:
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' ) ;
Tee 是朝着正确方向迈出的一步,但这会将其发送到文件而不是文件多变的.我想我可以读取该文件,但直接将其保存在那里会更简单.
Tee is a step in the right direction but this sends it to a file rather than to a variable. I guess I could then read the file but it would be simpler to get it straight there.
推荐答案
您要捕获::小
use Capture::Tiny 'tee';
my $output = tee { system( "some command" ) };
我写它来代替Tee和其他约20个执行某种捕获功能但又以一种或另一种方式存在缺陷的模块.
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)
-- xdg (aka dagolden)
这篇关于如何将Perl输出发送到STDOUT和变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文