Python subprocess 模块,list2cmdline() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用subprocess.list2cmdline()

项目:benchmarks    作者:tensorflow    | 项目源码 | 文件源码
def CreatePods(pod_name, yaml_file):
  """Creates pods based on the given kubernetes config.

  Args:
    pod_name: 'name-prefix' selector for the pods.
    yaml_file: kubernetes yaml config.

  Raises:
    TimeoutError: if jobs didn't come up for a long time.
  """
  command = [_KUBECTL, 'create', '--filename=%s' % yaml_file]
  logging.info('Creating pods: %s', subprocess.list2cmdline(command))
  subprocess.check_call(command)

  if not _WaitUntil(100, _GetPodNames, pod_name):
    raise TimeoutError(
        'Timed out waiting for %s pod to come up.' % pod_name)
项目:wib    作者:chengsoonong    | 项目源码 | 文件源码
def call(self, args, devnull=False):
        """Call other processes.
        args - list of command args
        devnull - whether to pipe stdout to /dev/null (or equivalent)
        """
        if self.debug:
            click.echo(subprocess.list2cmdline(args))
            click.confirm('Continue?', default=True, abort=True)
        try:
            kwargs = {}
            if devnull:
                # Pipe to /dev/null (or equivalent).
                kwargs['stderr'] = subprocess.STDOUT
                kwargs['stdout'] = self.FNULL
            ret_code = subprocess.call(args, **kwargs)
        except subprocess.CalledProcessError:
            return False
        return ret_code
项目:ATX    作者:NetEaseGame    | 项目源码 | 文件源码
def run_adb(*args, **kwargs):
    cmds = ['adb']
    serialno = kwargs.get('serialno', None)
    if serialno:
        cmds.extend(['-s', serialno])
    host = kwargs.get('host')
    if host:
        cmds.extend(['-H', host])
    port = kwargs.get('port')
    if port:
        cmds.extend(['-P', str(port)])
    cmds.extend(args)
    cmds = map(str, cmds)
    cmdline = subprocess.list2cmdline(cmds)
    try:
        return check_output(cmdline, shell=True)
    except Exception, e:
        raise EnvironmentError('run cmd: {} failed. {}'.format(cmdline, e))
项目:pyVSR    作者:georgesterpu    | 项目源码 | 文件源码
def _gen_wordnet(self, wdnet):

        if self._languageModel is True:
            new_hmmlist = append_to_file(self._viseme_list, ('!ENTER', '!EXIT'))
            self._viseme_dict = append_to_file(self._viseme_dict, ('!ENTER []', '!EXIT []'))

            cmd = ['HLStats -b ./run/bigrams -o ' + self._viseme_list + ' ' + self._labels]
            print(list2cmdline(cmd))
            run(cmd, check=True, shell=True)

            cmd = ['HBuild -n ./run/bigrams ' + new_hmmlist + ' ' + wdnet]
            print(list2cmdline(cmd))
            run(cmd, check=True, shell=True)
            self._word_net = wdnet

        else:
            cmd = ['HParse', self._grammar, wdnet]
            print(list2cmdline(cmd))
            run(cmd, check=True)
            self._word_net = wdnet
项目:AutomatorX    作者:xiaoyaojjian    | 项目源码 | 文件源码
def run_adb(*args, **kwargs):
    cmds = ['adb']
    serialno = kwargs.get('serialno', None)
    if serialno:
        cmds.extend(['-s', serialno])
    host = kwargs.get('host')
    if host:
        cmds.extend(['-H', host])
    port = kwargs.get('port')
    if port:
        cmds.extend(['-P', str(port)])
    cmds.extend(args)
    cmds = map(str, cmds)
    cmdline = subprocess.list2cmdline(cmds)
    try:
        return check_output(cmdline, shell=False)
    except Exception, e:
        raise EnvironmentError('run cmd: {} failed. {}'.format(cmdline, e))
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_list2cmdline(self):
        self.assertEqual(subprocess.list2cmdline(['a b c', 'd', 'e']),
                         '"a b c" d e')
        self.assertEqual(subprocess.list2cmdline(['ab"c', '\\', 'd']),
                         'ab\\"c \\ d')
        self.assertEqual(subprocess.list2cmdline(['ab"c', ' \\', 'd']),
                         'ab\\"c " \\\\" d')
        self.assertEqual(subprocess.list2cmdline(['a\\\\\\b', 'de fg', 'h']),
                         'a\\\\\\b "de fg" h')
        self.assertEqual(subprocess.list2cmdline(['a\\"b', 'c', 'd']),
                         'a\\\\\\"b c d')
        self.assertEqual(subprocess.list2cmdline(['a\\\\b c', 'd', 'e']),
                         '"a\\\\b c" d e')
        self.assertEqual(subprocess.list2cmdline(['a\\\\b\\ c', 'd', 'e']),
                         '"a\\\\b\\ c" d e')
        self.assertEqual(subprocess.list2cmdline(['ab', '']),
                         'ab ""')
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_list2cmdline(self):
        self.assertEqual(subprocess.list2cmdline(['a b c', 'd', 'e']),
                         '"a b c" d e')
        self.assertEqual(subprocess.list2cmdline(['ab"c', '\\', 'd']),
                         'ab\\"c \\ d')
        self.assertEqual(subprocess.list2cmdline(['ab"c', ' \\', 'd']),
                         'ab\\"c " \\\\" d')
        self.assertEqual(subprocess.list2cmdline(['a\\\\\\b', 'de fg', 'h']),
                         'a\\\\\\b "de fg" h')
        self.assertEqual(subprocess.list2cmdline(['a\\"b', 'c', 'd']),
                         'a\\\\\\"b c d')
        self.assertEqual(subprocess.list2cmdline(['a\\\\b c', 'd', 'e']),
                         '"a\\\\b c" d e')
        self.assertEqual(subprocess.list2cmdline(['a\\\\b\\ c', 'd', 'e']),
                         '"a\\\\b\\ c" d e')
        self.assertEqual(subprocess.list2cmdline(['ab', '']),
                         'ab ""')
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_list2cmdline(self):
        self.assertEqual(subprocess.list2cmdline(['a b c', 'd', 'e']),
                         '"a b c" d e')
        self.assertEqual(subprocess.list2cmdline(['ab"c', '\\', 'd']),
                         'ab\\"c \\ d')
        self.assertEqual(subprocess.list2cmdline(['ab"c', ' \\', 'd']),
                         'ab\\"c " \\\\" d')
        self.assertEqual(subprocess.list2cmdline(['a\\\\\\b', 'de fg', 'h']),
                         'a\\\\\\b "de fg" h')
        self.assertEqual(subprocess.list2cmdline(['a\\"b', 'c', 'd']),
                         'a\\\\\\"b c d')
        self.assertEqual(subprocess.list2cmdline(['a\\\\b c', 'd', 'e']),
                         '"a\\\\b c" d e')
        self.assertEqual(subprocess.list2cmdline(['a\\\\b\\ c', 'd', 'e']),
                         '"a\\\\b\\ c" d e')
        self.assertEqual(subprocess.list2cmdline(['ab', '']),
                         'ab ""')
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_list2cmdline(self):
        self.assertEqual(subprocess.list2cmdline(['a b c', 'd', 'e']),
                         '"a b c" d e')
        self.assertEqual(subprocess.list2cmdline(['ab"c', '\\', 'd']),
                         'ab\\"c \\ d')
        self.assertEqual(subprocess.list2cmdline(['ab"c', ' \\', 'd']),
                         'ab\\"c " \\\\" d')
        self.assertEqual(subprocess.list2cmdline(['a\\\\\\b', 'de fg', 'h']),
                         'a\\\\\\b "de fg" h')
        self.assertEqual(subprocess.list2cmdline(['a\\"b', 'c', 'd']),
                         'a\\\\\\"b c d')
        self.assertEqual(subprocess.list2cmdline(['a\\\\b c', 'd', 'e']),
                         '"a\\\\b c" d e')
        self.assertEqual(subprocess.list2cmdline(['a\\\\b\\ c', 'd', 'e']),
                         '"a\\\\b\\ c" d e')
        self.assertEqual(subprocess.list2cmdline(['ab', '']),
                         'ab ""')
项目:python-    作者:secondtonone1    | 项目源码 | 文件源码
def nt_quote_arg(arg):
    """Quote a command line argument according to Windows parsing rules"""
    return subprocess.list2cmdline([arg])
项目:python-    作者:secondtonone1    | 项目源码 | 文件源码
def install_options(self, script_text):
        self.options = shlex.split(self._extract_options(script_text))
        cmdline = subprocess.list2cmdline(self)
        if not isascii(cmdline):
            self.options[:0] = ['-x']
项目:python-    作者:secondtonone1    | 项目源码 | 文件源码
def _render(items):
        cmdline = subprocess.list2cmdline(
            CommandSpec._strip_quotes(item.strip()) for item in items)
        return '#!' + cmdline + '\n'


# For pbr compat; will be removed in a future version.
项目:my-first-blog    作者:AnkurBegining    | 项目源码 | 文件源码
def nt_quote_arg(arg):
    """Quote a command line argument according to Windows parsing rules"""
    return subprocess.list2cmdline([arg])
项目:my-first-blog    作者:AnkurBegining    | 项目源码 | 文件源码
def install_options(self, script_text):
        self.options = shlex.split(self._extract_options(script_text))
        cmdline = subprocess.list2cmdline(self)
        if not isascii(cmdline):
            self.options[:0] = ['-x']
项目:my-first-blog    作者:AnkurBegining    | 项目源码 | 文件源码
def _render(items):
        cmdline = subprocess.list2cmdline(
            CommandSpec._strip_quotes(item.strip()) for item in items)
        return '#!' + cmdline + '\n'


# For pbr compat; will be removed in a future version.
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def nt_quote_arg(arg):
    """Quote a command line argument according to Windows parsing rules"""
    return subprocess.list2cmdline([arg])
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def install_options(self, script_text):
        self.options = shlex.split(self._extract_options(script_text))
        cmdline = subprocess.list2cmdline(self)
        if not isascii(cmdline):
            self.options[:0] = ['-x']
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def _render(items):
        cmdline = subprocess.list2cmdline(
            CommandSpec._strip_quotes(item.strip()) for item in items)
        return '#!' + cmdline + '\n'


# For pbr compat; will be removed in a future version.
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def nt_quote_arg(arg):
    """Quote a command line argument according to Windows parsing rules"""
    return subprocess.list2cmdline([arg])
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def install_options(self, script_text):
        self.options = shlex.split(self._extract_options(script_text))
        cmdline = subprocess.list2cmdline(self)
        if not isascii(cmdline):
            self.options[:0] = ['-x']
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def _render(items):
        cmdline = subprocess.list2cmdline(items)
        return '#!' + cmdline + '\n'

# For pbr compat; will be removed in a future version.
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def nt_quote_arg(arg):
    """Quote a command line argument according to Windows parsing rules"""
    return subprocess.list2cmdline([arg])
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def install_options(self, script_text):
        self.options = shlex.split(self._extract_options(script_text))
        cmdline = subprocess.list2cmdline(self)
        if not isascii(cmdline):
            self.options[:0] = ['-x']
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def nt_quote_arg(arg):
    """Quote a command line argument according to Windows parsing rules"""
    return subprocess.list2cmdline([arg])
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def install_options(self, script_text):
        self.options = shlex.split(self._extract_options(script_text))
        cmdline = subprocess.list2cmdline(self)
        if not isascii(cmdline):
            self.options[:0] = ['-x']
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def _render(items):
        cmdline = subprocess.list2cmdline(items)
        return '#!' + cmdline + '\n'

# For pbr compat; will be removed in a future version.
项目:jira_worklog_scanner    作者:pgarneau    | 项目源码 | 文件源码
def nt_quote_arg(arg):
    """Quote a command line argument according to Windows parsing rules"""
    return subprocess.list2cmdline([arg])
项目:jira_worklog_scanner    作者:pgarneau    | 项目源码 | 文件源码
def install_options(self, script_text):
        self.options = shlex.split(self._extract_options(script_text))
        cmdline = subprocess.list2cmdline(self)
        if not isascii(cmdline):
            self.options[:0] = ['-x']
项目:jira_worklog_scanner    作者:pgarneau    | 项目源码 | 文件源码
def _render(items):
        cmdline = subprocess.list2cmdline(
            CommandSpec._strip_quotes(item.strip()) for item in items)
        return '#!' + cmdline + '\n'


# For pbr compat; will be removed in a future version.
项目:zanph    作者:zanph    | 项目源码 | 文件源码
def nt_quote_arg(arg):
    """Quote a command line argument according to Windows parsing rules"""
    return subprocess.list2cmdline([arg])
项目:zanph    作者:zanph    | 项目源码 | 文件源码
def install_options(self, script_text):
        self.options = shlex.split(self._extract_options(script_text))
        cmdline = subprocess.list2cmdline(self)
        if not isascii(cmdline):
            self.options[:0] = ['-x']
项目:zanph    作者:zanph    | 项目源码 | 文件源码
def _render(items):
        cmdline = subprocess.list2cmdline(items)
        return '#!' + cmdline + '\n'

# For pbr compat; will be removed in a future version.
项目:glog-cli    作者:globocom    | 项目源码 | 文件源码
def __call__(self, *args):
        command = "{cmd} {args}".format(cmd=self._command,
                                        args=subprocess.list2cmdline(args))
        output = subprocess.check_output(command,
                                         shell=self._shell,
                                         cwd=self._cwd,
                                         stderr=subprocess.STDOUT,
                                         universal_newlines=True)
        return self._yield_output(output)
项目:Sci-Finder    作者:snverse    | 项目源码 | 文件源码
def nt_quote_arg(arg):
    """Quote a command line argument according to Windows parsing rules"""
    return subprocess.list2cmdline([arg])
项目:Sci-Finder    作者:snverse    | 项目源码 | 文件源码
def install_options(self, script_text):
        self.options = shlex.split(self._extract_options(script_text))
        cmdline = subprocess.list2cmdline(self)
        if not isascii(cmdline):
            self.options[:0] = ['-x']
项目:Sci-Finder    作者:snverse    | 项目源码 | 文件源码
def _render(items):
        cmdline = subprocess.list2cmdline(
            CommandSpec._strip_quotes(item.strip()) for item in items)
        return '#!' + cmdline + '\n'


# For pbr compat; will be removed in a future version.
项目:Sci-Finder    作者:snverse    | 项目源码 | 文件源码
def nt_quote_arg(arg):
    """Quote a command line argument according to Windows parsing rules"""
    return subprocess.list2cmdline([arg])
项目:Sci-Finder    作者:snverse    | 项目源码 | 文件源码
def install_options(self, script_text):
        self.options = shlex.split(self._extract_options(script_text))
        cmdline = subprocess.list2cmdline(self)
        if not isascii(cmdline):
            self.options[:0] = ['-x']
项目:widget-ts-cookiecutter    作者:jupyter-widgets    | 项目源码 | 文件源码
def list2cmdline(cmd_list):
        return ' '.join(map(pipes.quote, cmd_list))
项目:widget-ts-cookiecutter    作者:jupyter-widgets    | 项目源码 | 文件源码
def run(cmd, **kwargs):
    """Echo a command before running it.  Defaults to repo as cwd"""
    log.info('> ' + list2cmdline(cmd))
    kwargs.setdefault('cwd', HERE)
    kwargs.setdefault('shell', os.name == 'nt')
    if not isinstance(cmd, (list, tuple)) and os.name != 'nt':
        cmd = shlex.split(cmd)
    cmd[0] = which(cmd[0])
    return subprocess.check_call(cmd, **kwargs)
项目:afl-kit    作者:kcwu    | 项目源码 | 文件源码
def afl_showmap(input_path, first=False):
    cmd = [
            'afl-showmap',
            '-m', str(args.memory_limit),
            '-t', str(args.time_limit),
            '-o', '-',
            '-Z']

    if args.qemu_mode:
        cmd += ['-Q']
    if args.edge_mode:
        cmd += ['-e']
    cmd += ['--', args.exe] + args.args

    input_from_file = False
    if args.stdin_file:
        input_from_file = True
        shutil.copy(input_path, args.stdin_file)
        input_path = args.stdin_file
    for i in range(len(cmd)):
        if '@@' in cmd[i]:
            input_from_file = True
            cmd[i] = cmd[i].replace('@@', input_path)

    if first:
        logger.debug('run command line: %s', subprocess.list2cmdline(cmd))
    if input_from_file:
        p = subprocess.Popen(cmd, stdout=subprocess.PIPE, bufsize=1048576)
    else:
        p = subprocess.Popen(cmd, stdin=file(input_path), stdout=subprocess.PIPE, bufsize=1048576)
    out = p.stdout.read()
    p.wait()
    #out = p.communicate()[0]

    a = array.array('l', map(int, out.split()))
    return a
项目:ascii-art-py    作者:blinglnav    | 项目源码 | 文件源码
def nt_quote_arg(arg):
    """Quote a command line argument according to Windows parsing rules"""
    return subprocess.list2cmdline([arg])
项目:ascii-art-py    作者:blinglnav    | 项目源码 | 文件源码
def install_options(self, script_text):
        self.options = shlex.split(self._extract_options(script_text))
        cmdline = subprocess.list2cmdline(self)
        if not isascii(cmdline):
            self.options[:0] = ['-x']
项目:ascii-art-py    作者:blinglnav    | 项目源码 | 文件源码
def _render(items):
        cmdline = subprocess.list2cmdline(
            CommandSpec._strip_quotes(item.strip()) for item in items)
        return '#!' + cmdline + '\n'


# For pbr compat; will be removed in a future version.
项目:dockwrkr    作者:turbulent    | 项目源码 | 文件源码
def run(container, containerArgs, config, basePath=None, networks=None):
    params = readCreateParameters(
        container, config, basePath=basePath, networks=networks, asList=True)
    if params.isFail():
        return params
    try:
        cmd = [DOCKER_CLIENT, "run", "--rm", "--interactive", "--tty"] + params.getOK() + containerArgs
        logger.debug("EXECVP - %s" % subprocess.list2cmdline(cmd))
        os.execvp(DOCKER_CLIENT, cmd)
    except Exception as ex:
        return Fail(ex)
项目:ivaochdoc    作者:ivaoch    | 项目源码 | 文件源码
def nt_quote_arg(arg):
    """Quote a command line argument according to Windows parsing rules"""
    return subprocess.list2cmdline([arg])
项目:ivaochdoc    作者:ivaoch    | 项目源码 | 文件源码
def install_options(self, script_text):
        self.options = shlex.split(self._extract_options(script_text))
        cmdline = subprocess.list2cmdline(self)
        if not isascii(cmdline):
            self.options[:0] = ['-x']
项目:ivaochdoc    作者:ivaoch    | 项目源码 | 文件源码
def _render(items):
        cmdline = subprocess.list2cmdline(
            CommandSpec._strip_quotes(item.strip()) for item in items)
        return '#!' + cmdline + '\n'


# For pbr compat; will be removed in a future version.
项目:aws-cfn-plex    作者:lordmuffin    | 项目源码 | 文件源码
def nt_quote_arg(arg):
    """Quote a command line argument according to Windows parsing rules"""
    return subprocess.list2cmdline([arg])
项目:aws-cfn-plex    作者:lordmuffin    | 项目源码 | 文件源码
def install_options(self, script_text):
        self.options = shlex.split(self._extract_options(script_text))
        cmdline = subprocess.list2cmdline(self)
        if not isascii(cmdline):
            self.options[:0] = ['-x']