开发者

how to clear out std and transfer stderr to std?

I have the following command in a bash script,

time=$((./a.out) 2>&1)

开发者_高级运维

When run it, there are some printout in std when running a.out alone. How to clear those printout and make $time variable only contain execution time?


time=$(./a.out 3>&1 1>/dev/null 2>&3)

This:

  1. redirects stderr to an unused stream (3),

  2. silences stdout

  3. redirects the temporary stream (3) to stdout

This is based on this answer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜