我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用subprocess.list2cmdline()。
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)
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
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))
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
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))
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 ""')
def nt_quote_arg(arg): """Quote a command line argument according to Windows parsing rules""" return subprocess.list2cmdline([arg])
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']
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.
def _render(items): cmdline = subprocess.list2cmdline(items) return '#!' + cmdline + '\n' # For pbr compat; will be removed in a future version.
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)
def list2cmdline(cmd_list): return ' '.join(map(pipes.quote, cmd_list))
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)
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
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)