0

I need my script to execute a binary file a number of times and get some statistics about its execution time using the the "time" directive. However the following code crashes:

cmd = ["time", "./executable", "<", "input_file"]
result = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.PIPE)

with the following message:

File "exec_script.py", line 15, in result = subprocess.Popen("time ./quake < small_input", stdout = subprocess.PIPE, stderr = subprocess.PIPE) File "/usr/lib/python2.7/subprocess.py", line 710, in init errread, errwrite) File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory

I have been cracking my skull for hours now and can't figure this out, any help? Note that if I just run that command from the same directory, it works. But not through the script.

3
  • 1
    You need shell=True to use features such as input redirection.
    – Alex Hall
    Jun 4, 2016 at 18:09
  • @AlexHall thanks! Can you help me as to why out = result.stdout.read() is "Usage: time [-apvV] [-f format] [-o file] [--append] [--verbose] [--portability] [--format=format] [--output=file] [--version] [--quiet] [--help] command [arg...]" ?
    – Xpl0
    Jun 4, 2016 at 18:25
  • I'm not sure but try using a single string instead of a list.
    – Alex Hall
    Jun 4, 2016 at 18:30

0

Your Answer

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

Browse other questions tagged or ask your own question.