1

I have next python code:

exec_cmd = "time"
print exec_cmd  
gzip_cmd = subprocess.Popen(exec_cmd, shell=True, stdout=subprocess.PIPE)
out = gzip_cmd.communicate()[0]
print out

When I try to execute this code I got next:

time
Usage: time [-apvV] [-f format] [-o file] [--append] [--verbose]
       [--portability] [--format=format] [--output=file] [--version]
       [--quiet] [--help] command [arg...]

But when I try to run this command in terminal I got:

time

real    0m0.000s
user    0m0.000s
sys     0m0.000s

So what is the problem?

1
  • Do you want to run a program/script named "time" in the same folder as your python script? Then you need to use "./time", because the current working directory in not in the $PATH in Un*x. Commented Jul 31, 2014 at 12:10

1 Answer 1

5

The "problem" is that time is a Bash built-in, so it's different between Bash and /bin/sh (assuming that's not an alias for Bash--it isn't in Debian/Ubuntu).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.