Run command on the device, returning the output.

        Args:
          command: Shell command to run
          timeout_ms: Maximum time to allow the command to run.
194503
def Shell(self, command, timeout_ms=None):
        
        return self.protocol_handler.Command(
            self._handle, service=b'shell', command=command,
            timeout_ms=timeout_ms)
411915
def runCmd(cls, cmd):
        
        cit.echo(cmd, "command")
        result = os.system(cmd)
        cls.checkResult(result)
1196881
def run(cmd):
    

    status, output = commands.getstatusoutput(cmd)
    if status:
        print(output)
    return status == 0
1142700
def run_command(args, asynchronous=False):
    """"""
    logging.info("Executing %s command %s.",
                 asynchronous and 'asynchronous' or 'synchronous', args)

    process = subprocess.Popen(args,
                               shell=True,
                               stdout=subprocess.PIPE,
                               stderr=subprocess.STDOUT)

    try:
        timeout = asynchronous and 1 or None
        output = process.communicate(timeout=timeout)[0].decode('utf8')
    except subprocess.TimeoutExpired:
        pass

    if asynchronous:
        return PopenOutput(None, 'Asynchronous call.')
    else:
        return PopenOutput(process.returncode, output)
231289
def StreamingShell(self, command, timeout_ms=None):
        
        return self.protocol_handler.StreamingCommand(
            self._handle, service=b'shell', command=command,
            timeout_ms=timeout_ms)
1370369
def _RunCommand(self, command):
    """"""
    arguments = shlex.split(command)
    process = subprocess.Popen(
        arguments, stderr=subprocess.PIPE, stdout=subprocess.PIPE,
        universal_newlines=True)
    if not process:
      raise RuntimeError("Running: {0:s} failed.".format(command))

    output, error = process.communicate()
    if process.returncode != 0:
      error = "\n".join(error.split("\n")[-5:])
      raise RuntimeError("Running: {0:s} failed with error:\n{1:s}.".format(
          command, error))

    return output
524900
def execute_command(cls, command):
        
        return Popen(
            command,
            stdout=PIPE,
            stderr=STDOUT,
            start_new_session=True
        )
1316316
def run_command(self, command):
        
        self.display = DISPLAYS["stdout"]
        self.conf["pagesize"] = 0
        self.onecmd(command)
129378
def sos_get_command_output(command, timeout=300, stderr=False,
                           chroot=None, chdir=None, env=None,
                           binary=False, sizelimit=None, poller=None):
    
    # Change root or cwd for child only. Exceptions in the prexec_fn
    # closure are caught in the parent (chroot and chdir are bound from
    # the enclosing scope).
    def _child_prep_fn():
        if (chroot):
            os.chroot(chroot)
        if (chdir):
            os.chdir(chdir)

    cmd_env = os.environ.copy()
    # ensure consistent locale for collected command output
    cmd_env['LC_ALL'] = 'C'
    # optionally add an environment change for the command
    if env:
        for key, value in env.items():
            if value:
                cmd_env[key] = value
            else:
                cmd_env.pop(key, None)
    # use /usr/bin/timeout to implement a timeout
    if timeout and is_executable("timeout"):
        command = "timeout %ds %s" % (timeout, command)

    # shlex.split() reacts badly to unicode on older python runtimes.
    if not six.PY3:
        command = command.encode('utf-8', 'ignore')
    args = shlex.split(command)
    # Expand arguments that are wildcard paths.
    expanded_args = []
    for arg in args:
        expanded_arg = glob.glob(arg)
        if expanded_arg:
            expanded_args.extend(expanded_arg)
        else:
            expanded_args.append(arg)
    try:
        p = Popen(expanded_args, shell=False, stdout=PIPE,
                  stderr=STDOUT if stderr else PIPE,
                  bufsize=-1, env=cmd_env, close_fds=True,
                  preexec_fn=_child_prep_fn)

        reader = AsyncReader(p.stdout, sizelimit, binary)
        if poller:
            while reader.running:
                if poller():
                    p.terminate()
                    raise SoSTimeoutError
        stdout = reader.get_contents()
        while p.poll() is None:
            pass

    except OSError as e:
        if e.errno == errno.ENOENT:
            return {'status': 127, 'output': ""}
        else:
            raise e

    if p.returncode == 126 or p.returncode == 127:
        stdout = six.binary_type(b"")

    return {
        'status': p.returncode,
        'output': stdout
    }
844948
def run(args: List[str],
        get_output: bool = False,
        encoding: str = sys.getdefaultencoding()) -> Tuple[str, str]:
    
    printable = " ".join(shlex.quote(x) for x in args).replace("\n", r"\n")
    log.debug("Running external command: {}", printable)
    if get_output:
        p = subprocess.run(args, stdout=subprocess.PIPE,
                           stderr=subprocess.PIPE, check=True)
        stdout, stderr = p.stdout.decode(encoding), p.stderr.decode(encoding)
    else:
        subprocess.check_call(args)
        stdout, stderr = "", ""
    return stdout, stderr
1142590
def _run_cmd_get_output(cmd):
    
    process = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
    out, err = process.communicate()
    return out or err
1321803
def run_command(args, cwd = None, shell = False, timeout = None, env = None):
    '''
    
    '''
    from subprocess import PIPE, Popen
    from StringIO import StringIO
    import fcntl, os, signal
    p = Popen(args, shell = shell, cwd = cwd, stdout = PIPE, stderr = PIPE, env = env)
    tstart = time.time()
    buf = StringIO()

    # try to make it non-blocking
    try:
        fcntl.fcntl(p.stdout, fcntl.F_SETFL, fcntl.fcntl(p.stdout, fcntl.F_GETFL) | os.O_NONBLOCK)
    except Exception:
        pass

    while True:
        time.sleep(0.1)
        retcode = p.poll()
        try:
            buf.write(p.stdout.read())
        except Exception:
            pass
        if retcode is not None:
            break
        if timeout is not None and time.time() > tstart + timeout:
            print("timeout in process %u" % p.pid)
            try: 
                os.kill(p.pid, signal.SIGKILL)
            except OSError:
                pass
            p.wait()
    return buf.getvalue()
504335
def _run_command(self, command):
        
        machine_name = self.frame_run_buttons.var_machine.get()
        self._run_dragonpy_cli("--machine", machine_name, command)
1197244
def run_local(self, commands):
        
        process = subprocess.Popen(
            commands.get('cli_command'),
            shell=self.shell,
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
        )

        out, err = process.communicate()

        # display app output
        self.run_display_app_output(out)
        self.run_display_app_errors(err)

        # Exit Code
        return self.run_exit_code(process.returncode)
604883
def _send_command(self, command):
        
        try:
            if isinstance(command, list):
                for cmd in command:
                    output = self.device.send_command(cmd)
                    if "% Invalid" not in output:
                        break
            else:
                output = self.device.send_command(command)
            return self._send_command_postprocess(output)
        except (socket.error, EOFError) as e:
            raise ConnectionClosedException(str(e))
319666
def run_shell(cmd, timeout=60, verbose=False):
    """"""
    retcode = None
    try:
        p = Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT, executable='/bin/bash')
        continue_running = True
    except Exception as e:
        yield("Failed: %s" % e)
        continue_running = False

    while continue_running:
        try:
            line = p.stdout.readline()
            if verbose and line:
                yield(line)
            elif line.strip():
                yield(line.strip())
        except Exception:
            pass

        try:
            data = irc.recv(4096)
        except Exception as e:
            data = ""
            retcode = p.poll()  # returns None while subprocess is running

        if '!cancel' in data:
            retcode = "Cancelled live output reading. You have to kill the process manually."
            yield "[X]: %s" % retcode
            break

        elif retcode is not None:
            try:
                line = p.stdout.read()
            except:
                retcode = "Too much output, read timed out. Process is still running in background."

            if verbose and line:
                yield line

            if retcode != 0:
                yield "[X]: %s" % retcode
            elif retcode == 0 and verbose:
                yield "[√]"

            break
915662
def run(self, bin, *args, **kwargs):
        
        bin = self._bin(bin)

        cmd = [bin] + list(args)
        shell = kwargs.get("shell", False)
        call = kwargs.pop("call", False)
        input_ = kwargs.pop("input_", None)

        if shell:
            cmd = list_to_shell_command(cmd)

        try:
            if self._is_windows:
                kwargs["shell"] = True

            if input_:
                p = subprocess.Popen(
                    cmd,
                    stdin=subprocess.PIPE,
                    stdout=subprocess.PIPE,
                    stderr=subprocess.STDOUT,
                    **kwargs
                )
                output = p.communicate(encode(input_))[0]
            elif call:
                return subprocess.call(cmd, stderr=subprocess.STDOUT, **kwargs)
            else:
                output = subprocess.check_output(
                    cmd, stderr=subprocess.STDOUT, **kwargs
                )
        except CalledProcessError as e:
            raise EnvCommandError(e)

        return decode(output)