我试图获得进程的时间,当我在shell中使用关键字time时,我得到了一个更好的输出:
real 0m0,430s
user 0m0,147s
sys 0m0,076s
而不是提供不同输出的/usr/bin/time
。 当我尝试使用subprocess.call('time command args',shell=true)
在Python的子进程库中运行它时,它给出了/usr/bin/time而不是关键字。 如何使用关键字函数,而不是当前的?
shell=true
导致子进程
使用/bin/sh
,而不是bash
。 您还需要executable
参数
subprocess.call('time command args', shell=True, executable='/bin/bash')
根据需要将路径调整到bash
。