0

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?

1 Answer 1

1

Use the return values from .communicate().

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

2 Comments

Do I need to access it through the communicate() that's already there? what do I output at the end? When I output h.stdout, it returns None
If you're using communicate() you might as well access it that way. The other option is to pass stdout=subprocess.PIPE to the Popen constructor, which will result in h.stdout being populated. But that's kind of overkill when you're already using communicate().

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.