In executing a time
command in bash (Ubuntu 18.04, python 3.6):
$ /usr/bin/time -f '%E' sleep 1
0:01.00
It returns the meausred time as expected. But with subprocess.run()
returns empty for the same command:
>>> subprocess.run("/usr/bin/time -f '%E' sleep 1", stdout=subprocess.PIPE, shell = True)
0:01.00
CompletedProcess(args="/usr/bin/time -f '%E' sleep 1", returncode=0, stdout=b'')
I'm not very familiar with the parameters of the function, and my questions are:
Why is the return from subprocess.run()
empty?
What's the correct way to use subprocess.run()
here?