perl-为线程进度生成漂亮的控制台输出
我的所有线程都希望将其进程打印到同一行终端。我不能让他们选择不同的路线。我怎么办?(linux和windows,如果可能的话) 编辑: 我尝试了两种变体: 一, 打印“\n”时,行会向下移动,\b不要擦除\n字符:perl-为线程进度生成漂亮的控制台输出,perl,terminal,console,printf,Perl,Terminal,Console,Printf,我的所有线程都希望将其进程打印到同一行终端。我不能让他们选择不同的路线。我怎么办?(linux和windows,如果可能的话) 编辑: 我尝试了两种变体: 一, 打印“\n”时,行会向下移动,\b不要擦除\n字符: if ( !($x % 10) ) { local $| = 1; # Or use IO::Handle; STDOUT->autoflush; # remove prev progress print "\b" x length($progres
if ( !($x % 10) )
{
local $| = 1; # Or use IO::Handle; STDOUT->autoflush;
# remove prev progress
print "\b" x length($progressString) if defined $progressString;
# do lots of processing, update $counter
$progressString = "Thread #$tid. $x / $length1"; # No more newline
print $progressString; # Will print, because auto-flush is on
}
二,
同样地
my $progress = Term::ProgressBar->new($length1);
$progress->update($x);
提前感谢您。我的脚本的工作变体如下:
use Win32::Console::ANSI; # for Windows and nothing for linux
# ...
#---OUTPUT----------------------
if ( !($x % 10) ) {
local $| = 1;
# Choose the line for thread ($i - thread_id)
print "\n" x $i;
# Remove prev. progress
print "\b" x length($progressString) if defined $progressString;
# Do lots of processing, update
$progressString = " Thread #$i. $x / $length1";
print $progressString; # Will print, because auto-flush is on
print "\e[A" x $i, "\r"; # Back to begin before printing
}
#-------------------------------
你说的“进步”是什么意思?一个点?一个角色?数字?数字或填充进度条。您可以在终端窗口上下移动光标,如下所述:这在
gnome terminal
中运行良好:perl-E'say“\E[1A123456789\E[0m”
。它将在终端中当前光标上方打印文本“123456789”
1行。我已经安装了“Win32::Console::ANSI”模块,现在看来,脚本正在工作。不知道它在Linux服务器中如何工作。谢谢您的建议。(正在工作的varint打印“\e[A”x$tid)