Python subprocess.list2cmdline() Examples

The following are code examples for showing how to use subprocess.list2cmdline(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don't like. You can also save this page to your account.

Example 1
Project: wib   Author: chengsoonong   File: cli.py    (GNU General Public License v3.0) View Source Project 7 votes vote down vote up
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 
Example 2
Project: benchmarks   Author: tensorflow   File: kubectl_util.py    (Apache License 2.0) View Source Project 6 votes vote down vote up
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) 
Example 3
Project: ATX   Author: NetEaseGame   File: minicap.py    (license) View Source Project 6 votes vote down vote up
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)) 
Example 4
Project: pyVSR   Author: georgesterpu   File: htk.py    (license) View Source Project 6 votes vote down vote up
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 
Example 5
Project: AutomatorX   Author: xiaoyaojjian   File: minicap.py    (license) View Source Project 6 votes vote down vote up
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)) 
Example 6
Project: zippy   Author: securesystemslab   File: test_subprocess.py    (license) View Source Project 6 votes vote down vote up
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 ""') 
Example 7
Project: oil   Author: oilshell   File: test_subprocess.py    (license) View Source Project 6 votes vote down vote up
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 ""') 
Example 8
Project: python2-tracer   Author: extremecoders-re   File: test_subprocess.py    (license) View Source Project 6 votes vote down vote up
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 ""') 
Example 9
Project: web_ctp   Author: molebot   File: test_subprocess.py    (license) View Source Project 6 votes vote down vote up
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 ""') 
Example 10
Project: python-   Author: secondtonone1   File: easy_install.py    (license) View Source Project 5 votes vote down vote up
def nt_quote_arg(arg):
    """Quote a command line argument according to Windows parsing rules"""
    return subprocess.list2cmdline([arg]) 
Example 11
Project: python-   Author: secondtonone1   File: easy_install.py    (license) View Source Project 5 votes vote down vote up
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'] 
Example 12
Project: python-   Author: secondtonone1   File: easy_install.py    (license) View Source Project 5 votes vote down vote up
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. 
Example 13
Project: my-first-blog   Author: AnkurBegining   File: easy_install.py    (license) View Source Project 5 votes vote down vote up
def nt_quote_arg(arg):
    """Quote a command line argument according to Windows parsing rules"""
    return subprocess.list2cmdline([arg]) 
Example 14
Project: my-first-blog   Author: AnkurBegining   File: easy_install.py    (license) View Source Project 5 votes vote down vote up
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'] 
Example 15
Project: my-first-blog   Author: AnkurBegining   File: easy_install.py    (license) View Source Project 5 votes vote down vote up
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. 
Example 16
Project: swjtu-pyscraper   Author: Desgard   File: easy_install.py    (MIT License) View Source Project 5 votes vote down vote up
def nt_quote_arg(arg):
    """Quote a command line argument according to Windows parsing rules"""
    return subprocess.list2cmdline([arg]) 
Example 17
Project: swjtu-pyscraper   Author: Desgard   File: easy_install.py    (MIT License) View Source Project 5 votes vote down vote up
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'] 
Example 18
Project: swjtu-pyscraper   Author: Desgard   File: easy_install.py    (MIT License) View Source Project 5 votes vote down vote up
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. 
Example 19
Project: noc-orchestrator   Author: DirceuSilvaLabs   File: easy_install.py    (MIT License) View Source Project 5 votes vote down vote up
def nt_quote_arg(arg):
    """Quote a command line argument according to Windows parsing rules"""
    return subprocess.list2cmdline([arg]) 
Example 20
Project: noc-orchestrator   Author: DirceuSilvaLabs   File: easy_install.py    (MIT License) View Source Project 5 votes vote down vote up
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'] 
Example 21
Project: noc-orchestrator   Author: DirceuSilvaLabs   File: easy_install.py    (MIT License) View Source Project 5 votes vote down vote up
def _render(items):
        cmdline = subprocess.list2cmdline(items)
        return '#!' + cmdline + '\n'

# For pbr compat; will be removed in a future version. 
Example 22
Project: noc-orchestrator   Author: DirceuSilvaLabs   File: easy_install.py    (MIT License) View Source Project 5 votes vote down vote up
def nt_quote_arg(arg):
    """Quote a command line argument according to Windows parsing rules"""
    return subprocess.list2cmdline([arg]) 
Example 23
Project: noc-orchestrator   Author: DirceuSilvaLabs   File: easy_install.py    (MIT License) View Source Project 5 votes vote down vote up
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'] 
Example 24
Project: noc-orchestrator   Author: DirceuSilvaLabs   File: easy_install.py    (MIT License) View Source Project 5 votes vote down vote up
def nt_quote_arg(arg):
    """Quote a command line argument according to Windows parsing rules"""
    return subprocess.list2cmdline([arg]) 
Example 25
Project: noc-orchestrator   Author: DirceuSilvaLabs   File: easy_install.py    (MIT License) View Source Project 5 votes vote down vote up
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'] 
Example 26
Project: noc-orchestrator   Author: DirceuSilvaLabs   File: easy_install.py    (MIT License) View Source Project 5 votes vote down vote up
def _render(items):
        cmdline = subprocess.list2cmdline(items)
        return '#!' + cmdline + '\n'

# For pbr compat; will be removed in a future version. 
Example 27
Project: jira_worklog_scanner   Author: pgarneau   File: easy_install.py    (license) View Source Project 5 votes vote down vote up
def nt_quote_arg(arg):
    """Quote a command line argument according to Windows parsing rules"""
    return subprocess.list2cmdline([arg]) 
Example 28
Project: jira_worklog_scanner   Author: pgarneau   File: easy_install.py    (license) View Source Project 5 votes vote down vote up
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'] 
Example 29
Project: jira_worklog_scanner   Author: pgarneau   File: easy_install.py    (license) View Source Project 5 votes vote down vote up
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. 
Example 30
Project: zanph   Author: zanph   File: easy_install.py    (license) View Source Project 5 votes vote down vote up
def nt_quote_arg(arg):
    """Quote a command line argument according to Windows parsing rules"""
    return subprocess.list2cmdline([arg]) 
Example 31
Project: zanph   Author: zanph   File: easy_install.py    (license) View Source Project 5 votes vote down vote up
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'] 
Example 32
Project: zanph   Author: zanph   File: easy_install.py    (license) View Source Project 5 votes vote down vote up
def _render(items):
        cmdline = subprocess.list2cmdline(items)
        return '#!' + cmdline + '\n'

# For pbr compat; will be removed in a future version. 
Example 33
Project: glog-cli   Author: globocom   File: _version.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 34
Project: Sci-Finder   Author: snverse   File: easy_install.py    (license) View Source Project 5 votes vote down vote up
def nt_quote_arg(arg):
    """Quote a command line argument according to Windows parsing rules"""
    return subprocess.list2cmdline([arg]) 
Example 35
Project: Sci-Finder   Author: snverse   File: easy_install.py    (license) View Source Project 5 votes vote down vote up
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'] 
Example 36
Project: Sci-Finder   Author: snverse   File: easy_install.py    (license) View Source Project 5 votes vote down vote up
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. 
Example 37
Project: Sci-Finder   Author: snverse   File: easy_install.py    (license) View Source Project 5 votes vote down vote up
def nt_quote_arg(arg):
    """Quote a command line argument according to Windows parsing rules"""
    return subprocess.list2cmdline([arg]) 
Example 38
Project: Sci-Finder   Author: snverse   File: easy_install.py    (license) View Source Project 5 votes vote down vote up
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'] 
Example 39
Project: widget-ts-cookiecutter   Author: jupyter-widgets   File: setupbase.py    (license) View Source Project 5 votes vote down vote up
def list2cmdline(cmd_list):
        return ' '.join(map(pipes.quote, cmd_list)) 
Example 40
Project: widget-ts-cookiecutter   Author: jupyter-widgets   File: setupbase.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 41
Project: afl-kit   Author: kcwu   File: afl-cmin.py    (license) View Source Project 5 votes vote down vote up
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 
Example 42
Project: ascii-art-py   Author: blinglnav   File: easy_install.py    (license) View Source Project 5 votes vote down vote up
def nt_quote_arg(arg):
    """Quote a command line argument according to Windows parsing rules"""
    return subprocess.list2cmdline([arg]) 
Example 43
Project: ascii-art-py   Author: blinglnav   File: easy_install.py    (license) View Source Project 5 votes vote down vote up
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'] 
Example 44
Project: ascii-art-py   Author: blinglnav   File: easy_install.py    (license) View Source Project 5 votes vote down vote up
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. 
Example 45
Project: dockwrkr   Author: turbulent   File: docker.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 46
Project: ivaochdoc   Author: ivaoch   File: easy_install.py    (license) View Source Project 5 votes vote down vote up
def nt_quote_arg(arg):
    """Quote a command line argument according to Windows parsing rules"""
    return subprocess.list2cmdline([arg]) 
Example 47
Project: ivaochdoc   Author: ivaoch   File: easy_install.py    (license) View Source Project 5 votes vote down vote up
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'] 
Example 48
Project: ivaochdoc   Author: ivaoch   File: easy_install.py    (license) View Source Project 5 votes vote down vote up
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. 
Example 49
Project: aws-cfn-plex   Author: lordmuffin   File: easy_install.py    (license) View Source Project 5 votes vote down vote up
def nt_quote_arg(arg):
    """Quote a command line argument according to Windows parsing rules"""
    return subprocess.list2cmdline([arg]) 
Example 50
Project: aws-cfn-plex   Author: lordmuffin   File: easy_install.py    (license) View Source Project 5 votes vote down vote up
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']