Script in Python to run a C program

Michael A. Miller mmiller3 at iupui.edu
Thu Sep 21 08:40:57 EDT 2000


>>>>> "The" == The Majestic Moined Mogul <mogul at primus.ca> writes:

    > Could someone please tell me how to best write a Python
    > script that could execute a C program several times and
    > compare the run times of each?

The commands module will help:

>>> import commands
>>> status1, result1 = commands.getstatusoutput('run my prog')
>>> status2, result2 = commands.getstatusoutput('run my prog again')

Your program output can be split into lines with 

>>> import string
>>> lines1 = string.split(result1, '\n')
>>> lines2 = string.split(result2, '\n')

And compared like this:

>>> while index in range(len(lines1)):
>>>    if lines1[index] <> lines2[index]:
>>>         print 'diference at', index
>>>         print lines1[index]
>>>         print lines2[index]

Mike

-- 
Michael A. Miller                      mmiller3 at iupui.edu
  Krannert Institute of Cardiology, IU School of Medicine
  Indiana Center for Vascular Biology and Medicine



More information about the Python-list mailing list