# HG changeset patch # User Joseph Turian # Date 1215029400 14400 # Node ID 0e3af3c53ac7dc5e1c18216d3b170bd17f04363d # Parent 9e73e6dc9823c4dabedb6c59e0c02fe9bff1c2d5 common.misc.runcmd can now take input diff -r 9e73e6dc9823 -r 0e3af3c53ac7 common/misc.py --- a/common/misc.py Wed Jul 02 15:42:42 2008 -0400 +++ b/common/misc.py Wed Jul 02 16:10:00 2008 -0400 @@ -1,13 +1,18 @@ -def runcmd(args): +def runcmd(args, input=None): """ Split args into a list, run this command, and return its output. Raise RuntimeError if the command does not return 0. + @note: This function will not work if args contains pipes | + @param input: If this exists, it will be fed as stdin """ import subprocess - print args +# print args import string - proc = subprocess.Popen(string.split(args), stdout=subprocess.PIPE) - output = proc.communicate()[0] + if input == None: stdin = None + else: stdin = subprocess.PIPE + proc = subprocess.Popen(string.split(args), stdout=subprocess.PIPE, stdin=stdin) +# proc = subprocess.Popen(string.split(args), stdout=subprocess.PIPE) + output = proc.communicate(input=input)[0] if proc.returncode != 0: import exceptions raise exceptions.RuntimeError