Example #1
0
def get_process_output(executable, args=(), env=None, path=None, reactor=None,
                 errortoo=None):
    """
    Spawn a process and return its output as a deferred returning a string.

    @param executable: The file name to run and get the output of - the
                       full path should be used.

    @param args: the command line arguments to pass to the process; a
                 sequence of strings. The first string should *NOT* be the
                 executable's name.

    @param env: the environment variables to pass to the processs; a
                dictionary of strings.

    @param path: the path to run the subprocess in - defaults to the
                 current directory.

    @param reactor: the reactor to use - defaults to the default reactor

    @param errortoo: If true, include stderr in the result.  If false, discard
        it. If None and stderr is received the returned L{Deferred} will
        errback with an L{IOError} instance with a C{processEnded} attribute.
        The C{processEnded} attribute refers to a L{Deferred} which fires when
        the executed process ends.
    """
    return _callProtocolWithDeferred(lambda d:
                                        _BackRelay(d, errortoo=errortoo),
                                     executable, args, env or {}, path,
                                     reactor)
def getSensibleProcessOutput(executable, args=(), env={}, path=None,
                             reactor=None):
    """
    Do what you would expect getProcessOutput to do:
    * if process emits stderr, capture it along with stdout
    * if process ends with exit code != 0 or signal, errback with combined process output
    * otherwise, callback with combined process output
    """
    return _callProtocolWithDeferred(SensibleProcessProtocol, executable, args, env, path,
                                     reactor)
Example #3
0
def getSensibleProcessOutput(executable, args=(), env={}, path=None,
                             reactor=None):
    """
    Do what you would expect getProcessOutput to do:
    * if process emits stderr, capture it along with stdout
    * if process ends with exit code != 0 or signal, errback with combined process output
    * otherwise, callback with combined process output
    """
    return _callProtocolWithDeferred(SensibleProcessProtocol, executable, args, env, path,
                                     reactor)