[Tutor] subprocess output

ashley at qxhp.com ashley at qxhp.com
Wed Jul 28 05:38:52 CEST 2010


I'm using Python 2.6.5 and I've got a challenge with the subprocess
module. I'd like the output to be stored in a variable, and not sent to
the stdout. The relevant lines as they are now:

#!/usr/bin/env python
import subprocess
import sys

dom = sys.argv[1]
switch = sys.argv [2]
answer = subprocess.call("whois " + dom, shell=True)

Execute the above (whatever.py -example.com -a1) prints the entire WHOIS
output, but I just want it saved to the variable 'answer', nothing more.

Changing 'shell=True' to 'shell=False' raises an exception and removing
the 'shell=' altogether is troublesome as well.

Thoughts on how I can accomplish this?

Thanks!




More information about the Tutor mailing list