Run App in Docker Container.

        Args:
            commands (dict): A dictionary of the CLI commands.

        Returns:
            int: The exit code of the subprocess command.
510331
def run_docker(self, commands):
        
        try:
            import docker
        except ImportError:
            print(
                '{}{}Could not import docker module (try "pip install docker").'.format(
                    c.Style.BRIGHT, c.Fore.RED
                )
            )
            sys.exit(1)

        # app_args = self.profile.get('profile_args').standard
        app_args_data = self.profile.get('profile_args').data
        install_json = self.profile.get('install_json')

        # client
        client = docker.from_env()

        # app data
        app_dir = os.getcwd()
        # app_path = '{}/{}'.format(app_dir, program_main)

        # ports
        ports = {}
        if self.args.vscd:
            ports = {'{}/tcp'.format(self.args.vscd_port): self.args.vscd_port}

        # volumes
        volumes = {}
        in_path = '{}/{}'.format(app_dir, app_args_data.get('tc_in_path'))
        if app_args_data.get('tc_in_path') is not None:
            volumes[in_path] = {'bind': in_path}
        log_path = '{}/{}'.format(app_dir, app_args_data.get('tc_log_path'))
        if app_args_data.get('tc_log_path') is not None:
            volumes[log_path] = {'bind': log_path}
        out_path = '{}/{}'.format(app_dir, app_args_data.get('tc_out_path'))
        if app_args_data.get('tc_out_path') is not None:
            volumes[out_path] = {'bind': out_path}
        temp_path = '{}/{}'.format(app_dir, app_args_data.get('tc_temp_path'))
        if app_args_data.get('tc_temp_path') is not None:
            volumes[temp_path] = {'bind': temp_path}
        volumes[app_dir] = {'bind': app_dir}

        if self.args.docker_image is not None:
            # user docker image from cli as an override.
            docker_image = self.args.docker_image
        else:
            # docker image from install.json can be overridden by docker image in profile. if no
            # image is defined in either file use the default image define as self.docker_image.
            docker_image = self.profile.get(
                'dockerImage', install_json.get('dockerImage', self.docker_image)
            )

        status_code = 1
        try:
            self.container = client.containers.run(
                docker_image,
                entrypoint=commands.get('cli_command'),
                environment=['PYTHONPATH={}/lib_latest'.format(app_dir)],
                detach=True,
                # network_mode=install_json.get('docker_host', 'host'),
                ports=ports,
                remove=True,
                volumes=volumes,
                working_dir=app_dir,
            )
            results = self.container.wait()
            status_code = results.get('StatusCode')
            error = results.get('Error')
            if error:
                print('{}{}{}'.format(c.Style.BRIGHT, c.Fore.RED, error))
        except Exception as e:
            print('{}{}{}'.format(c.Style.BRIGHT, c.Fore.RED, e))
            sys.exit()

        # Exit Code
        return self.run_exit_code(status_code)
413109
def run_subprocess(command):
    
    x = Popen(command, shell=True, stdout=PIPE, stderr=PIPE)
    out, err = x.communicate()
    out = out.decode('utf-8')
    err = err.decode('utf-8')
    return out, err
545995
def run(cmds, **kwargs):
    
    proc = sp.Popen(cmds, bufsize=-1, stdout=sp.PIPE, stderr=sp.STDOUT,
                    close_fds=sys.platform != 'win32')
    for line in proc.stdout:
        print(line[:-1].decode())
    retcode = proc.wait()
    if retcode:
        raise sp.CalledProcessError(retcode, cmds)
626498
def _run(name,
         cmd,
         exec_driver=None,
         output=None,
         stdin=None,
         python_shell=True,
         output_loglevel='debug',
         ignore_retcode=False,
         use_vt=False,
         keep_env=None):
    '''
    
    '''
    if exec_driver is None:
        exec_driver = _get_exec_driver()
    ret = __salt__['container_resource.run'](
        name,
        cmd,
        container_type=__virtualname__,
        exec_driver=exec_driver,
        output=output,
        stdin=stdin,
        python_shell=python_shell,
        output_loglevel=output_loglevel,
        ignore_retcode=ignore_retcode,
        use_vt=use_vt,
        keep_env=keep_env)

    if output in (None, 'all'):
        return ret
    else:
        return ret[output]
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
1155226
def runcmd(command, command_input=None, cwd=None):
    """"""
    proc = subprocess.Popen(command, stdin=subprocess.PIPE,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE,
                            cwd=cwd)
    (stdout, stderr) = proc.communicate(command_input)
    if proc.returncode != 0:
        sys.stderr.write('ABORTING: command "%s" failed w/ code %s:\n'
                         '%s\n%s' % (command, proc.returncode,
                                     stdout, stderr))
        sys.exit(proc.returncode)
    return proc.returncode, stdout, stderr
405299
def _run_cmd(cmd):
    '''
    
    '''
    ret = {}
    env_vars = {
        'KAPACITOR_URL': _get_url(),
        'KAPACITOR_UNSAFE_SSL': __salt__['config.option']('kapacitor.unsafe_ssl', 'false'),
    }
    result = __salt__['cmd.run_all'](cmd, env=env_vars)

    if result.get('stdout'):
        ret['stdout'] = result['stdout']
    if result.get('stderr'):
        ret['stderr'] = result['stderr']
    ret['success'] = result['retcode'] == 0

    return ret
1263550
def run_command(self, args):
        
        parsed_args = self.parser.parse_args(args)
        if hasattr(parsed_args, 'func'):
            parsed_args.func(parsed_args)
        else:
            self.parser.print_help()
1185352
def run_command(cmd):
    
    child = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE,
                             stdin=subprocess.PIPE, stdout=subprocess.PIPE)
    out = [s.decode("utf-8").strip() for s in child.stdout]
    err = [s.decode("utf-8").strip() for s in child.stderr]
    w = child.wait()
    return os.WEXITSTATUS(w), out, err
432825
def run(self, **kwargs):
        
        for key in kwargs:
            setattr(self, key, kwargs[key])
        self.command = self.COMMAND_RUN
1371951
def run(command, input=None, exit=0, shell=False):
        
        if isinstance(input, str):
            input = input.encode()

        # Only pipe stdin if we have input to pipe.
        stdin = {} if input is None else {"stdin": subprocess.PIPE}
        try:
            child = subprocess.Popen(command, stdout=subprocess.PIPE,
                                     stderr=subprocess.PIPE, **stdin)
        except FileNotFoundError as e:
            # Extract name of command.
            name = command.split(' ', 1)[0] if isinstance(command, str) else command[0]
            raise DependencyError(name)

        stdout, _ = child.communicate(input=input)
        if exit is not None and child.returncode != exit:
            raise Error("failed to stylecheck code")
        return stdout.decode()
891629
def run(self, command):
        
        boto.log.debug('running:%s on %s' % (command, self.server.instance_id))
        status = 0
        try:
            t = self._ssh_client.exec_command(command)
        except paramiko.SSHException:
            status = 1
        std_out = t[1].read()
        std_err = t[2].read()
        t[0].close()
        t[1].close()
        t[2].close()
        boto.log.debug('stdout: %s' % std_out)
        boto.log.debug('stderr: %s' % std_err)
        return (status, std_out, std_err)
401905
def run_command(cmd, *args):
    
    command = ' '.join((cmd, args))
    p = Popen(command, shell=True, stdout=PIPE, stderr=PIPE)
    stdout, stderr = p.communicate()
    return p.retcode, stdout, stderr
614469
def run(self, params):
        

        self.params = list(reversed(params))

        if not self.params:
            self.help()
            return

        while self.params:
            p = self.params.pop()

            if p in self.command:
                # If we got a known command, execute it.
                self.command[p](self)

            elif os.path.exists(p):
                # If we were given the name of an existing file, read it.
                self.read_moc(p)

            else:
                # Otherwise raise an error.
                raise CommandError('file or command {0} not found'.format(p))
621160
def execute_command(self, cmd):
        
        if self.input_mode:
            self.end_input(cmd)
            return
        if cmd.endswith('\n'):
            cmd = cmd[:-1]
        # cls command
        if cmd == 'cls':
            self.clear_terminal()
            return
        self.run_command(cmd)
30127
def run_with_codes(command)
      # pid, stdin, stdout, stderr = Open4::popen4(command)
      # ignored, status = Process::waitpid2 pid
      # exit_code = status.to_i
      exit_signal = nil
      
      stdout_data = ''
      stderr_data = ''
      status = POpen4::popen4(command) do |stdout, stderr, stdin, pid|
        stdin.close
        stdout_data = stdout.read
        stderr_data = stderr.read.strip
      end

      exit_code = status ? status.exitstatus : 0

      return stdout_data, stderr_data, exit_code, exit_signal
    end
332793
def command_run(self, command):
        
        # convert the command to sequence if a string
        if isinstance(command, basestring):
            command = shlex.split(command)
        try:
            return Popen(command, stdout=PIPE, stderr=PIPE, close_fds=True).wait()
        except Exception as e:
            # make a pretty command for error loggings and...
            if isinstance(command, basestring):
                pretty_cmd = command
            else:
                pretty_cmd = " ".join(command)
            msg = "Command `{cmd}` {error}".format(cmd=pretty_cmd, error=e.errno)
            raise exceptions.CommandError(msg, error_code=e.errno)