third_party/blink/tools/blinkpy/common/system/executive.py
def run_command(
            self,
            args,
            cwd=None,
            env=None,
            input=None,  # pylint: disable=redefined-builtin
            timeout_seconds=None,
            error_handler=None,
            return_exit_code=False,
            return_stderr=True,
            ignore_stderr=False,
            decode_output=True,
            debug_logging=True):
        """Popen wrapper for convenience and to work around python bugs.

        By default, run_command will expect a zero exit code and will return the
        program output in that case, or throw a ScriptError if the program has a
        non-zero exit code. This behavior can be changed by setting the
        appropriate input parameters.

        Args:
            args: the program arguments. Passed to Popen.
            cwd: the current working directory for the program. Passed to Popen.
            env: the environment for the program. Passed to Popen.
            input: input to give to the program on stdin. Accepts either a file
                handler (will be passed directly) or a string (will be passed
                via a pipe).
            timeout_seconds: maximum time in seconds to wait for the program to
                terminate; on a timeout the process will be killed
            error_handler: a custom error handler called with a ScriptError when
                the program fails. The default handler raises the error.
            return_exit_code: instead of returning the program output, return
                the exit code. Setting this makes non-zero exit codes non-fatal
                (the error_handler will not be called).
            return_stderr: if True, include stderr in the returned output. If
                False, stderr will be printed to the console unless ignore_stderr
                is also True.
            ignore_stderr: squash stderr so it doesn't appear in the console.
            decode_output: whether to decode the program output.
            debug_logging: whether to log details about program execution.
        """
        assert isinstance(args, list) or isinstance(args, tuple)
        start_time = time.time()

        assert not (return_stderr and ignore_stderr)
        stdin, string_to_communicate = self._compute_stdin(input)
        stderr = self.STDOUT if return_stderr else (
            self.DEVNULL if ignore_stderr else None)

        process = self.popen(
            args,
            stdin=stdin,
            stdout=self.PIPE,
            stderr=stderr,
            cwd=cwd,
            env=env,
            close_fds=self._should_close_fds())

        def on_command_timeout():
            _log.error('Error: Command timed out after %s seconds',
                       timeout_seconds)
            process.kill()

        if timeout_seconds:
            timer = threading.Timer(timeout_seconds, on_command_timeout)
            timer.start()

        output = process.communicate(string_to_communicate)[0]

        # run_command automatically decodes to unicode() unless explicitly told not to.
        if decode_output:
            output = output.decode(
                self._child_process_encoding(), errors='replace')

        # wait() is not threadsafe and can throw OSError due to:
        # http://bugs.python.org/issue1731717
        exit_code = process.wait()

        if timeout_seconds:
            timer.cancel()

        if debug_logging:
            _log.debug('"%s" took %.2fs', self.command_for_printing(args),
                       time.time() - start_time)

        if return_exit_code:
            return exit_code

        if exit_code:
            script_error = ScriptError(
                script_args=args,
                exit_code=exit_code,
                output=output,
                cwd=cwd,
                output_limit=self.error_output_limit)
            (error_handler or self.default_error_handler)(script_error)
        return output
Popen wrapper for convenience and to work around python bugs.

        By default, run_command will expect a zero exit code and will return the
        program output in that case, or throw a ScriptError if the program has a
        non-zero exit code. This behavior can be changed by setting the
        appropriate input parameters.

        Args:
            args: the program arguments. Passed to Popen.
            cwd: the current working directory for the program. Passed to Popen.
            env: the environment for the program. Passed to Popen.
            input: input to give to the program on stdin. Accepts either a file
                handler (will be passed directly) or a string (will be passed
                via a pipe).
            timeout_seconds: maximum time in seconds to wait for the program to
                terminate; on a timeout the process will be killed
            error_handler: a custom error handler called with a ScriptError when
                the program fails. The default handler raises the error.
            return_exit_code: instead of returning the program output, return
                the exit code. Setting this makes non-zero exit codes non-fatal
                (the error_handler will not be called).
            return_stderr: if True, include stderr in the returned output. If
                False, stderr will be printed to the console unless ignore_stderr
                is also True.
            ignore_stderr: squash stderr so it doesn't appear in the console.
            decode_output: whether to decode the program output.
            debug_logging: whether to log details about program execution.
        
Popen wrapper for convenience and to work around python bugs.
By default, run_command will expect a zero exit code and will return the
program output in that case, or throw a ScriptError if the program has a
non-zero exit code. This behavior can be changed by setting the
appropriate input parameters.
Popen wrapper for convenience and to work around python bugs . By default run_command will expect a zero exit code and will return the program output in that case or throw a ScriptError if the program has a non - zero exit code . This behavior can be changed by setting the appropriate input parameters .
def run_command(
            self,
            args,
            cwd=None,
            env=None,
            input=None,  
            timeout_seconds=None,
            error_handler=None,
            return_exit_code=False,
            return_stderr=True,
            ignore_stderr=False,
            decode_output=True,
            debug_logging=True):
        assert isinstance(args, list) or isinstance(args, tuple)
        start_time = time.time()
        assert not (return_stderr and ignore_stderr)
        stdin, string_to_communicate = self._compute_stdin(input)
        stderr = self.STDOUT if return_stderr else (
            self.DEVNULL if ignore_stderr else None)
        process = self.popen(
            args,
            stdin=stdin,
            stdout=self.PIPE,
            stderr=stderr,
            cwd=cwd,
            env=env,
            close_fds=self._should_close_fds())
        def on_command_timeout():
            _log.error('Error: Command timed out after %s seconds',
                       timeout_seconds)
            process.kill()
        if timeout_seconds:
            timer = threading.Timer(timeout_seconds, on_command_timeout)
            timer.start()
        output = process.communicate(string_to_communicate)[0]
        if decode_output:
            output = output.decode(
                self._child_process_encoding(), errors='replace')
        exit_code = process.wait()
        if timeout_seconds:
            timer.cancel()
        if debug_logging:
            _log.debug('"%s" took %.2fs', self.command_for_printing(args),
                       time.time() - start_time)
        if return_exit_code:
            return exit_code
        if exit_code:
            script_error = ScriptError(
                script_args=args,
                exit_code=exit_code,
                output=output,
                cwd=cwd,
                output_limit=self.error_output_limit)
            (error_handler or self.default_error_handler)(script_error)
        return output
def run_command ( self , args , cwd = None , env = None , input = None , timeout_seconds = None , error_handler = None , return_exit_code = False , return_stderr = True , ignore_stderr = False , decode_output = True , debug_logging = True ) : assert isinstance ( args , list ) or isinstance ( args , tuple ) start_time = time . time ( ) assert not ( return_stderr and ignore_stderr ) stdin , string_to_communicate = self . _compute_stdin ( input ) stderr = self . STDOUT if return_stderr else ( self . DEVNULL if ignore_stderr else None ) process = self . popen ( args , stdin = stdin , stdout = self . PIPE , stderr = stderr , cwd = cwd , env = env , close_fds = self . _should_close_fds ( ) ) def on_command_timeout ( ) : _log . error ( 'Error: Command timed out after %s seconds' , timeout_seconds ) process . kill ( ) if timeout_seconds : timer = threading . Timer ( timeout_seconds , on_command_timeout ) timer . start ( ) output = process . communicate ( string_to_communicate ) [ 0 ] if decode_output : output = output . decode ( self . _child_process_encoding ( ) , errors = 'replace' ) exit_code = process . wait ( ) if timeout_seconds : timer . cancel ( ) if debug_logging : _log . debug ( '"%s" took %.2fs' , self . command_for_printing ( args ) , time . time ( ) - start_time ) if return_exit_code : return exit_code if exit_code : script_error = ScriptError ( script_args = args , exit_code = exit_code , output = output , cwd = cwd , output_limit = self . error_output_limit ) ( error_handler or self . default_error_handler ) ( script_error ) return output
Popen wrapper for convenience and to work around python bugs.
Popen wrapper for convenience and to work around python bugs .
# pylint: disable=redefined-builtin """Popen wrapper for convenience and to work around python bugs.

        By default, run_command will expect a zero exit code and will return the
        program output in that case, or throw a ScriptError if the program has a
        non-zero exit code. This behavior can be changed by setting the
        appropriate input parameters.

        Args:
            args: the program arguments. Passed to Popen.
            cwd: the current working directory for the program. Passed to Popen.
            env: the environment for the program. Passed to Popen.
            input: input to give to the program on stdin. Accepts either a file
                handler (will be passed directly) or a string (will be passed
                via a pipe).
            timeout_seconds: maximum time in seconds to wait for the program to
                terminate; on a timeout the process will be killed
            error_handler: a custom error handler called with a ScriptError when
                the program fails. The default handler raises the error.
            return_exit_code: instead of returning the program output, return
                the exit code. Setting this makes non-zero exit codes non-fatal
                (the error_handler will not be called).
            return_stderr: if True, include stderr in the returned output. If
                False, stderr will be printed to the console unless ignore_stderr
                is also True.
            ignore_stderr: squash stderr so it doesn't appear in the console.
            decode_output: whether to decode the program output.
            debug_logging: whether to log details about program execution.
        """ # run_command automatically decodes to unicode() unless explicitly told not to. # wait() is not threadsafe and can throw OSError due to: # http://bugs.python.org/issue1731717
self
args
the program arguments. Passed to Popen.
the program arguments . Passed to Popen .
cwd
the current working directory for the program. Passed to Popen.
the current working directory for the program . Passed to Popen .
env
the environment for the program. Passed to Popen.
the environment for the program . Passed to Popen .
input
input to give to the program on stdin. Accepts either a file
handler (will be passed directly) or a string (will be passed
via a pipe).
input to give to the program on stdin . Accepts either a file handler ( will be passed directly ) or a string ( will be passed via a pipe ) .
timeout_seconds
maximum time in seconds to wait for the program to
terminate; on a timeout the process will be killed
maximum time in seconds to wait for the program to terminate ; on a timeout the process will be killed
error_handler
a custom error handler called with a ScriptError when
the program fails. The default handler raises the error.
a custom error handler called with a ScriptError when the program fails . The default handler raises the error .
return_exit_code
instead of returning the program output, return
the exit code. Setting this makes non-zero exit codes non-fatal
(the error_handler will not be called).
instead of returning the program output return the exit code . Setting this makes non - zero exit codes non - fatal ( the error_handler will not be called ) .
return_stderr
if True, include stderr in the returned output. If
False, stderr will be printed to the console unless ignore_stderr
is also True.
if True include stderr in the returned output . If False stderr will be printed to the console unless ignore_stderr is also True .
ignore_stderr
squash stderr so it doesn't appear in the console.
squash stderr so it doesn ' t appear in the console .
decode_output
whether to decode the program output.
whether to decode the program output .
debug_logging
whether to log details about program execution.
whether to log details about program execution .