提问者:小点点

Python子进程时间调用/usr/bin/time而不是关键字


我试图获得进程的时间,当我在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而不是关键字。 如何使用关键字函数,而不是当前的?


共1个答案

匿名用户

shell=true导致子进程使用/bin/sh,而不是bash。 您还需要executable参数

subprocess.call('time command args', shell=True, executable='/bin/bash')

根据需要将路径调整到bash