How to ignore program's output when using /usr/bin/time?

前端 未结 2 2053
渐次进展
渐次进展 2021-01-13 23:43

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/t

2条回答
  •  轮回少年
    2021-01-14 00:31

    (Unable to comment)

    It might be nicer to use a subshell:

    /usr/bin/time ( ./program > /dev/null 2>&1 ) 2>&1
    

    Or better yet a compound construct:

    /usr/bin/time { ./program > /dev/null 2>&1; } 2>&1
    

提交回复
热议问题