将 pv 输出 (stderr) 打印到文件 [英] Print pv output (stderr) to file

查看:45
本文介绍了将 pv 输出 (stderr) 打印到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何打印 输出 到文件?例如:

timeout 5s dd if=/dev/random |pv -r >/开发/空[ 505kiB/s]

速率线输出在我的五秒超时过程中更新".我试过了,但它不起作用(日志为空):

timeout 5s dd if=/dev/random |pv -r >/dev/null 2>费率日志

我相信它与 输出,但一小时后我卡住了.理想情况下,我的日志文件每次都会有多行 打印一个新值:

[ 505kiB/s][ 498kiB/s][ 542kiB/s][ 513kiB/s][ 509kiB/s]

更新:

为了将内容放入我上面描述的文件中,我必须使用 虽然我不确定为什么需要它( 单独不起作用,如果没有 ):

timeout 5s dd if=/dev/random |pv -fr >/dev/null 2>>(stdbuf -oL tr '\r' '\n' >rates.log)

解决方案

来自 man pv:

<块引用>
-f, --force
力输出.通常情况下,pv 不会输出任何视觉显示如果标准错误不是终端.此选项强制它这样做.

由于 rates.log 不是终端,您需要执行 pv -fr 而不是 pv -r.

How can I print the output of to a file? For example:

timeout 5s dd if=/dev/random | pv -r > /dev/null
[ 505kiB/s]

The rate line output is "updated" over the course of my five second timeout. I tried this but it does not work (log is empty):

timeout 5s dd if=/dev/random | pv -r > /dev/null 2> rates.log

I believe it has something to do with carriage returns in the output, but after an hour I am stuck. Ideally my log file would have multiple lines each time prints a new value:

[ 505kiB/s]
[ 498kiB/s]
[ 542kiB/s]
[ 513kiB/s]
[ 509kiB/s]

UPDATE:

To get the content into a file as I described above I had to use though I'm not sure why it is required ( alone didn't work, the file will be empty without ):

timeout 5s dd if=/dev/random | pv -fr > /dev/null 2> >(stdbuf -oL tr '\r' '\n' > rates.log)

解决方案

From man pv:

-f, --force
Force output. Normally, pv will not output any visual display if standard error is not a terminal. This option forces it to do so.

Since rates.log isn't a terminal, you need to do pv -fr instead of pv -r.

这篇关于将 pv 输出 (stderr) 打印到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆