我想在这里将粗体hi!打印到STDERR。使用Term::Screen可以做到吗?
#!/usr/bin/env perl
use warnings;
use 5.12.0;
use utf8;
binmode STDOUT, ':utf8';
binmode STDERR, ':utf8';
use Term::Screen;
my $scr = new Term::Screen;
unless ( $scr ) { die " Something's wrong \n"; }
$scr->clrscr();
$scr->at(5,10)->bold()->puts("hi!")->normal();
$scr->at(11,0);发布于 2012-02-11 20:55:09
Screen,查看其源代码,是硬编码的,不能写入*STDOUT
例如,您正在调用的sub at{}在源代码中具有以下内容:
$this->term()->Tgoto( 'cm', $c, $r, *STDOUT );
因此,您需要显式地将所有STDOUT重定向到STDERR:
open(my $backup_stdout, ">&STDOUT");
close(STDOUT);
open(STDOUT, ">&STDERR"); # This affects ALL of spawned child processes!
# *STDOUT = *STDERR; # This does the same but ONLY affects your processhttps://stackoverflow.com/questions/9238801
复制相似问题