Mercurial > pylearn
changeset 360:0e3af3c53ac7
common.misc.runcmd can now take input
author | Joseph Turian <turian@iro.umontreal.ca> |
---|---|
date | Wed, 02 Jul 2008 16:10:00 -0400 |
parents | 9e73e6dc9823 |
children | f45456cdfb87 9e84e8a20a75 |
files | common/misc.py |
diffstat | 1 files changed, 9 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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