Reputation: 33
I'm trying to call the shell keyword version of 'time' via
subprocess.check_output('time ls',stderr=subprocess.STDOUT,shell=True)
this is giving me the output (which is /usr/bin/time output):
0.00user 0.00system 0:00.00elapsed ?%CPU (0avgtext+0avgdata 1992maxresident)k
0inputs+0outputs (0major+85minor)pagefaults 0swaps
rather than the shell keyword output:
real 0m0.001s
user 0m0.000s
sys 0m0.000s
For some reason subprocess.check_output is using the /usr/bin/time version of time.
Could someone tell me what is happening here? Thank you.
Upvotes: 0
Views: 80
Reputation: 5031
It is because time
is a also a built in function in Bash. So you need to specify that you want to use Bash as your shell:
print subprocess.check_output('time ls', stderr=subprocess.STDOUT,\
shell=True, executable='/bin/bash')
Upvotes: 2