我在组合python,time和tee方面遇到了一些问题。
我有一个脚本 script.sh ,其中包含以下行:
{ time python extractPassRate.py -i DataPaths/background.list -o PassRates/background.csv ; } 2>&1 | tee log.log
然而,当我这样做时:
source script.sh
终端只是挂起。
有趣的是,当我用以下代码替换该行:
{ time python extractPassRate.py ; } 2>&1 | tee log.log
(也就是说,如果我删除了python脚本参数) 或
{ time python extractPassRate.py -i DataPaths/background.list -o PassRates/background.csv ; } 2>&1
(不保存到log.log)
脚本有效。
第一行有问题吗?
答案 0 :(得分:0)
在Google上找到解决方案,马修阿尔珀特: How to redirect output to a file and stdout
这似乎是由于缓冲问题造成的。
马修的回答说:
程序unbuffer,expect包的一部分,将解决问题 缓冲问题。这将导致stdout和stderr写入 立即屏幕和文件,并在组合时保持同步 并重定向到发球台。 E.g:
$ unbuffer program [arguments ...] 2>& 1 | tee outfile
这对我有用