MyNameIsKhan
MyNameIsKhan

Reputation: 2612

Using Python to grab output from a C++ program (thru cout)

I have the following code in Python

import subprocess
import time

info = subprocess.STARTUPINFO()
info.dwFlags |= subprocess.STARTF_USESHOWWINDOW
info.wShowWindow = subprocess.SW_HIDE

t1 = time.clock()
h = subprocess.Popen([r"C:\Users\MyName\Desktop\test.exe"], startupinfo=info) 
h.communicate()
t2 = time.clock()-t1

print "Return Code:", h.returncode
print "Duration:", t2

This works great if I am looking for the program's return code but what if I want to grab things that the program simply cout's to the screen and manipulate them as variables in Python?

Upvotes: 0

Views: 102

Answers (1)

Amber
Amber

Reputation: 526623

Use the return values from .communicate().

Upvotes: 1

Related Questions