linux命令代碼time <command> | tail -n2,我希望提取sys時間和使用時間的行,但是,我得到如下:
time picat slater-6_sat ver2 "0"
輸出是:
winner = 4 with the least cost = 0
CPU time 0.0 seconds.
success
real 0m0.054s
user 0m0.035s
sys 0m0.019s
而當我只輸入picat slater-6_sat ver2 "0"
輸出是:
winner = 4 with the least cost = 0
CPU time 0.0 seconds.
success
我期待輸入 time picat slater-6_sat ver2 "0" | tail -n2,
輸出是:
user 0m0.035s
sys 0m0.019s
然而,事實是:
success
real 0m0.054s
user 0m0.035s
sys 0m0.019s
我猜原因是處理器認為時間,所以picat slater-6_sat ver2 "0"| tail -n2當作命令
我該如何解決這個問題?
uj5u.com熱心網友回復:
你可以嘗試這樣的事情:
(time picat slater-6_sat ver2 "0") > output.txt 2>&1 && tail -2 output.txt
在此處查看類似的答案:Output time to file with unix "time" command, but leave the output of command to console
這是一個示例 python 檔案:
from time import sleep
for x in range(0,10):
sleep(0.4)
print(x)
現在像這樣運行檔案:
$ (time python3 test.py) > output.txt 2>&1 && tail -2 output.txt
user 0m0.026s
sys 0m0.004s
其他資源:
- 做什么
2>&1?在shell中,“ 2>&1 ”是什么意思? - 做什么
&&?https://serverfault.com/questions/53577/linux-bash-syntax-meaning-of-and
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/471510.html
