[英]In Perl, how to clone output to stdout and a log file in real time
我想同時將輸出克隆到控制台以及日志文件。 這是我的代碼片段:
open STDOUT, ">>", "temp.txt" or die "";
system("echo This is a sample output..........");
但是,這里我只在temp.txt
輸出而不是在控制台上輸出。 你能建議一個解決方案嗎? 我正在使用Windows。
它將輸出到STDOUT
和temp.txt
,
use Capture::Tiny::Extended 'tee';
tee(
sub {
system("echo This is a sample output..........");
},
{ stdout => "temp.txt" }
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.