def callProc(cmd, keepLastNewLine=False): """call a process and return stdout, exception with stderr in message. The cmd is either a list of command and arguments, or pipeline, specified by a list of lists of commands and arguments.""" stdout = Pipeline.DataReader() pl = Pipeline.Procline(cmd, stdin="/dev/null", stdout=stdout) pl.wait() out = stdout.get() if (not keepLastNewLine) and (len(out) > 0) and (out[-1] == "\n"): out = out[0:-1] return out
def runProc(cmd, stdin="/dev/null", stdout=None, stderr=None, noError=False): """run a process, with I/O redirection to specified file paths or open file objects. None specifies inheriting. If noError is True, then the exit code is returned rather than generating an error""" # FIXME: drop noError??? pl = Pipeline.Procline(cmd, stdin=stdin, stdout=stdout, stderr=stderr) code = 0 try: pl.wait() except Pipeline.ProcException, ex: code = ex.returncode if not noError: raise