[英]Shell script: time and python into a file
我需要编写一个bash脚本,该脚本执行python程序,并且我需要在同一文件中输出执行时间和结果。 我无法编辑python代码。
由于存在多个测试,因此我想在后台执行它们。 我已经试过了
#!bin/bash
$(time python3 program.py file1 > solAndTimeFile1.txt &)
但它根本不起作用,它仅在solAndTimeFile1.txt中输出python程序的结果,并且时间在终端中显示。
我也尝试过这个:
#!bin/bash
$(time python3 program.py file1 > solAndTimeFile1.txt >> solAndTimeFile1.txt &)
相同的输出对我来说意义更小。
将命令放在花括号中,以便在子外壳程序中运行该命令,您可以捕获其输出。 要将stdout和stderr都重定向到文件,请使用&>file
。 有关更多信息,请参见man bash
。
{ time python3 program.py file1; } &>solAndTimeFile1.txt &
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.