我可以通过Whiptail来跟踪rsync的进度,使用Awk来解析rsync输出,然而,我很困惑为什么Perl的对应部分不能工作( Whiptail的量规停留在0)。
这是working Awk命令行:
rsync --info=progress2 --no-inc-recursive --human-readable <source> <destination> |
stdbuf -o0 awk -v RS='\r' '$2 ~ /%$/ { print substr($2, 0, length($2) - 1) }' |
whiptail --gauge Syncing 20 80 0这是Perl (我假设)的等价物:
rsync --info=progress2 --no-inc-recursive --human-readable <source> <destination> |
stdbuf -o0 perl -lne 'BEGIN { $/ = "\r" } print /(\d+)%/' |
whiptail --gauge Syncing 20 80 0如果我从Perl版本中删除Whiptail命令,则会按预期打印百分比数字。
如何修改Perl版本?
发布于 2019-10-04 00:09:27
你可能是suffering from buffering。尝试在STDOUT上设置autoflush。
BEGIN { $/ = "\r"; $|++ }或者,如果Perl的版本至少为5.14,或者添加了-MIO::Handle开关,您可以更明确地说明:
BEGIN { $/ = "\r"; *STDOUT->autoflush }https://stackoverflow.com/questions/58222955
复制相似问题