使用/usr/bin/time时如何忽略程序的输出? [英] How to ignore program's output when using /usr/bin/time?

查看:123
本文介绍了使用/usr/bin/time时如何忽略程序的输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道一个程序运行了多长时间,所以我尝试了"/usr/bin/time ./program>/dev/null". 但是很快我发现它向stderr显示了程序的输出.我尝试了"/usr/bin/time ./program>/dev/null 2>& 1",但是/usr/bin/time的输出没有出现. 所以我的问题是,如何忽略程序的输出,并保持时间的输出.

I want to know how long a program running, so I tried "/usr/bin/time ./program > /dev/null". But soon I found it displays program's output to stderr. I tried "/usr/bin/time ./program > /dev/null 2>&1" then, but /usr/bin/time's output not appear. So my question is, how to ignore program's output, and keep time's output.

非常感谢.

推荐答案

使用-o标志将输出信息不时地发送到其他内容,然后再发送给stderr.例如,如果您仍要在屏幕上显示它:

Use the -o flag to send the output from time to something else then stderr. For example, if you still want it on screen:

/usr/bin/time -o /dev/tty ./program >/dev/null 2>&1

或者,如果您非常想在stdout上输出:

Or, if you want output on stdout very badly:

/usr/bin/time sh -c './program >/dev/null 2>&1'

或类似.但是,现在您还正在测量外壳程序开始该过程的时间,这可能是问题也可能不是问题.

or similar. However, now you're also measuring the shell's time to start the process, which may or may not be a problem.

这篇关于使用/usr/bin/time时如何忽略程序的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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