2012-02-11 47 views
2

我想在這裏打印出大致的hi!STDERR。這可能與Term::Screen如何使用Term :: Screen打印到STDERR?

#!/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); 
+0

你能不能解釋一下那將是有益的?我很難看到你想要做什麼。 – Mat 2012-02-11 11:10:39

+0

我想這樣做(從'IO :: Interactive'文檔):「你也可以傳遞交互式的可寫文件句柄,在這種情況下,如果文件句柄連接到終端,它會寫入該文件句柄(而不是writinbg * STDOUT)。再一次,通常的犯罪嫌疑人是* STDERR:「 – 2012-02-12 14:03:24

回答

4

期限::屏幕,看着它的來源,是硬編碼寫入*STDOUT

例如sub at{}您呼叫,在源中,有這樣的:

$this->term()->Tgoto('cm', $c, $r, *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 process 
相關問題