Python - store output of subprocess() call in a string

Posted by Mark on Stack Overflow See other posts from Stack Overflow or by Mark
Published on 2010-03-23T19:05:01Z Indexed on 2010/03/23 19:13 UTC
Read the original article Hit count: 294

Filed under:
|

Hey all, I'm trying to make a system call in Python and store the output to a string that I can manipulate in the Python program.

#!/usr/bin/python

import subprocess

p = subprocess.Popen("pwd")

# edit - actual command I want to store output of
p2 = subprocess.Popen("ntpq -p")

I've tried a few things including some of the suggestions here:

http://stackoverflow.com/questions/1996518/retrieving-the-output-of-subprocess-call

but without any luck.

Many thanks!

© Stack Overflow or respective owner

Related posts about python

Related posts about output