Пример #1
0
 def run(self, cli):
     """
     Runs a command line.
     @param cli: Command line to run
     @param shell: True if command line is executed in a shell. False otherwise.
     @return: ProcessRunner instance
     """
     self._processrunner = ProcessRunner(stdout=self._stdout,
                                         stderr=self._stderr)
     self._processrunner.run(cli,
                             stdin=self._stdin,
                             shell=self._shell, cwd=None)
Пример #2
0
class CLRunner(object):
    """
    Runs a command line.
    """
    def __init__(self, stdin=None, stdout=None, stderr=None, shell=True):
        """
        Constructor
        @param: stdout Standard output as subprocess.PIPE or an existing file
                descriptor (a positive integer) or an existing file object
                or None
        @param: stdin Standard input as subprocess.PIPE or an existing file
                descriptor (a positive integer) or an existing file object
                or None
        @param: stderr Standard error as subprocess.PIPE or an existing file
                descriptor (a positive integer) or an existing file object
                or None
        """
        self._stdout = stdout
        self._stdin = stdin
        self._stderr = stderr
        self._processrunner = None
        self._shell = shell

    def run(self, cli):
        """
        Runs a command line.
        @param cli: Command line to run
        @param shell: True if command line is executed in a shell. False otherwise.
        @return: ProcessRunner instance
        """
        self._processrunner = ProcessRunner(stdout=self._stdout,
                                            stderr=self._stderr)
        self._processrunner.run(cli,
                                stdin=self._stdin,
                                shell=self._shell, cwd=None)

    def returnCode(self):
        """
        Returns the process return code.
        @return Process's return code. See subprocess.Popen interface for this 
                parameter's valid values.
        """
        return self._processrunner.returnCode()

    def finished(self):
        """
        Indicates if this instance's command line is finished.
        @return: True if CL was executed and has finished.
                Otherwise False.
        """
        if not self._processrunner:
            return False
        else:
            return self._processrunner.finished()

    def stdout(self):
        """
        Returns the standard output
        @return: Standard output as subprocess.PIPE or an existing file
                descriptor (a positive integer) or an existing file object
                or None
        """
        if self._processrunner:
            return self._processrunner.stdout()
        else:
            return None

    def stderr(self):
        """
        Returns the standard error
        @return: Standard error as subprocess.PIPE or an existing file
                descriptor (a positive integer) or an existing file object
                or None
        """
        if self._processrunner:
            return self._processrunner.stderr()
        else:
            return None