开发者

how to clear out std and transfer stderr to std?

开发者 https://www.devze.com 2023-03-20 18:24 出处:网络
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

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

精彩评论

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