Use commands
. Here is the documentation http://docs.python.org/2/library/commands.html
commands.getstatusoutput
returns a stdout output from your C program. So, if your program prints something, use that. (In fact, it returns a tuple (0, out) for stdout).
commands.getstatus
returns boolean status from program which you can use as well.
So, assuming you are using stdout to capture the ./program
output, the entire modified program looks like
import commands
while TRUE:
strlen += 1
output = commands.getstatusoutput("./program " + "A"*strlen)
outstatus = output[1]
if output == "true":
break
I would experiment with getstatus
to see if I can read values returned by program
.
Edit: Didn't notice that commands
is deprecated since 2.6 Please use subprocess
as shown in other response.