當前位置: 首頁>>代碼示例>>Python>>正文


Python subprocess.list2cmdline方法代碼示例

本文整理匯總了Python中subprocess.list2cmdline方法的典型用法代碼示例。如果您正苦於以下問題:Python subprocess.list2cmdline方法的具體用法?Python subprocess.list2cmdline怎麽用?Python subprocess.list2cmdline使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在subprocess的用法示例。


在下文中一共展示了subprocess.list2cmdline方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run_command

# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import list2cmdline [as 別名]
def run_command(command, args=[], cwd=None, env=None, name='command'):
    def cmd_args_to_str(cmd_args):
        return ' '.join([arg if not ' ' in arg else '"%s"' % arg for arg in cmd_args])

    assert isinstance(command, str) and isinstance(args, list)
    args = [command] + args

    check_call_args = {}
    if cwd is not None:
        check_call_args['cwd'] = cwd
    if env is not None:
        check_call_args['env'] = env

    import subprocess
    try:
        print('Running command \'%s\': %s' % (name, subprocess.list2cmdline(args)))
        subprocess.check_call(args, **check_call_args)
        print('Command \'%s\' completed successfully' % name)
    except subprocess.CalledProcessError as e:
        raise BuildError('\'%s\' exited with error code: %s' % (name, e.returncode)) 
開發者ID:godotengine,項目名稱:godot-mono-builds,代碼行數:22,代碼來源:os_utils.py

示例2: main

# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import list2cmdline [as 別名]
def main():
    args = make_args()
    config = configparser.ConfigParser()
    utils.load_config(config, args.config)
    for cmd in args.modify:
        utils.modify_config(config, cmd)
    with open(os.path.expanduser(os.path.expandvars(args.logging)), 'r') as f:
        logging.config.dictConfig(yaml.load(f))
    if args.run is None:
        buffer = io.StringIO()
        config.write(buffer)
        args.run = hashlib.md5(buffer.getvalue().encode()).hexdigest()
    logging.info('cd ' + os.getcwd() + ' && ' + subprocess.list2cmdline([sys.executable] + sys.argv))
    train = Train(args, config)
    train()
    logging.info(pybenchmark.stats) 
開發者ID:ruiminshen,項目名稱:yolo2-pytorch,代碼行數:18,代碼來源:train.py

示例3: test_list2cmdline

# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import list2cmdline [as 別名]
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 ""') 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:19,代碼來源:test_subprocess.py

示例4: _run

# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import list2cmdline [as 別名]
def _run(self, args, stdout_checker):
        process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        stdout, stderr = process.communicate()
        stdout = stdout.decode()
        try:
            self.assertEqual(0, process.returncode)
            stdout_checker(stdout)
        except Exception as e:
            # print output and rethrow exception
            print(subprocess.list2cmdline(args))
            print("--- stdout ---")
            for line in stdout.splitlines():
                print(line)
            print("--- stderr ---")
            for line in stderr.splitlines():
                print(line)
            print("--- end ---")

            raise e 
開發者ID:aws,項目名稱:aws-iot-device-sdk-python-v2,代碼行數:21,代碼來源:test_samples.py

示例5: time_cmd

# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import list2cmdline [as 別名]
def time_cmd(cmd, cwd=None, env=None, timeout=None):
    """Calculates and outputs the time a command takes.

    Args:
        cmd (list): Command to be run.
        cwd (str): Working directory command is to be executed in.
        env (dict): Working environment command is to be executed in.
        timeout (int): Timeout for the command.
    """
    if not env:
        env = deepcopy(os.environ)

    logger.info("\nRunning `%s` now..\n", " ".join(cmd))
    cmd_start = time.time()

    cmd = subprocess.run(cmd, check=False, cwd=cwd, env=env, timeout=timeout)

    cmd_end = time.time()
    logger.info("\n`%s` took %.3f seconds.\n", subprocess.list2cmdline(cmd.args), cmd_end - cmd_start) 
開發者ID:MozillaSecurity,項目名稱:funfuzz,代碼行數:21,代碼來源:repos_update.py

示例6: generate_pcm_audio_stereo

# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import list2cmdline [as 別名]
def generate_pcm_audio_stereo(name, sample_rate = 48000, duration = 2,  sample_format='pcm_s16le', fmt='wav'):
    # this default value for `fmt` looks like a mistake but we preserve it here

    outfile = os.path.join(sample_dir(), '%s.%s' % (name,fmt) )

    cmd = [FFMPEG_EXEC,'-y', '-f', 'lavfi', '-i', 'aevalsrc=sin(420*2*PI*t)|cos(430*2*PI*t):s=%d:d=%f'% ( sample_rate, duration)]

    #mono
    #cmd = ['ffmpeg','-y', '-f', 'lavfi', '-i', 'aevalsrc=sin(420*2*PI*t)::s=48000:d=10']

    cmd.extend([ '-f',fmt, '-acodec', sample_format])

    cmd.extend([outfile])

    p = subprocess.Popen(cmd, stdout = subprocess.PIPE,stderr = subprocess.PIPE)
    stdout,stderr = p.communicate()

    if p.returncode != 0:
        print(subprocess.list2cmdline(cmd))
        print(stderr)
        return Exception("error encoding footage")
    return outfile 
開發者ID:markreidvfx,項目名稱:pyaaf2,代碼行數:24,代碼來源:common.py

示例7: execute

# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import list2cmdline [as 別名]
def execute(args: List[str], check: bool = True, env: Dict[str, str] = None):
    if not env:
        env = os.environ.copy()
    env = env.copy()
    env["PYTHONUNBUFFERED "] = "1"

    call = subprocess.check_call if check else subprocess.call

    LOGGER.info("Launching command: {0}".format(subprocess.list2cmdline(args)))
    sys.stdout.write("----------\n")
    sys.stdout.flush()

    error = None
    try:
        call(args, env=env)
    except subprocess.CalledProcessError as e:
        error = e

    sys.stdout.write("----------\n")
    sys.stdout.flush()

    if error:
        raise error 
開發者ID:adferrand,項目名稱:dnsrobocert,代碼行數:25,代碼來源:utils.py

示例8: _open_subprocess

# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import list2cmdline [as 別名]
def _open_subprocess(self):
        # Force bufsize=0 on all Python versions to avoid writing the
        # unflushed buffer when closing a broken input pipe
        args = self._create_arguments()
        if is_win32:
            fargs = args
        else:
            fargs = subprocess.list2cmdline(args)
        log.debug(u"Opening subprocess: {0}".format(fargs))

        self.player = subprocess.Popen(maybe_encode(args, get_filesystem_encoding()),
                                       stdin=self.stdin, bufsize=0,
                                       stdout=self.stdout,
                                       stderr=self.stderr)
        # Wait 0.5 seconds to see if program exited prematurely
        if not self.running:
            raise OSError("Process exited prematurely")

        if self.namedpipe:
            self.namedpipe.open("wb")
        elif self.http:
            self.http.open() 
開發者ID:streamlink,項目名稱:streamlink,代碼行數:24,代碼來源:output.py

示例9: find_default_player

# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import list2cmdline [as 別名]
def find_default_player():
    if "darwin" in sys.platform:
        paths = os.environ.get("PATH", "").split(":")
        paths += ["/Applications/VLC.app/Contents/MacOS/"]
        paths += ["~/Applications/VLC.app/Contents/MacOS/"]
        path = check_paths(("VLC", "vlc"), paths)
    elif "win32" in sys.platform:
        exename = "vlc.exe"
        paths = os.environ.get("PATH", "").split(";")
        path = check_paths((exename,), paths)

        if not path:
            subpath = "VideoLAN\\VLC\\"
            envvars = ("PROGRAMFILES", "PROGRAMFILES(X86)", "PROGRAMW6432")
            paths = filter(None, (os.environ.get(var) for var in envvars))
            paths = (os.path.join(p, subpath) for p in paths)
            path = check_paths((exename,), paths)
    else:
        paths = os.environ.get("PATH", "").split(":")
        path = check_paths(("vlc",), paths)

    if path:
        # Quote command because it can contain space
        return subprocess.list2cmdline([path]) 
開發者ID:streamlink,項目名稱:streamlink,代碼行數:26,代碼來源:player.py

示例10: list2cmdline

# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import list2cmdline [as 別名]
def list2cmdline(cmd_list):
        return ' '.join(map(pipes.quote, cmd_list)) 
開發者ID:jupyter-widgets,項目名稱:jupyterlab-sidecar,代碼行數:4,代碼來源:setupbase.py

示例11: run

# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import list2cmdline [as 別名]
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) 
開發者ID:jupyter-widgets,項目名稱:jupyterlab-sidecar,代碼行數:11,代碼來源:setupbase.py

示例12: processcommand

# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import list2cmdline [as 別名]
def processcommand(cls, reader, command, replace=True):
        posargs = getattr(reader, "posargs", "")
        if sys.platform.startswith("win"):
            posargs_string = list2cmdline([x for x in posargs if x])
        else:
            posargs_string = " ".join([shlex_quote(x) for x in posargs if x])

        # Iterate through each word of the command substituting as
        # appropriate to construct the new command string. This
        # string is then broken up into exec argv components using
        # shlex.
        if replace:
            newcommand = ""
            for word in CommandParser(command).words():
                if word == "{posargs}" or word == "[]":
                    newcommand += posargs_string
                    continue
                elif word.startswith("{posargs:") and word.endswith("}"):
                    if posargs:
                        newcommand += posargs_string
                        continue
                    else:
                        word = word[9:-1]
                new_arg = ""
                new_word = reader._replace(word)
                new_word = reader._replace(new_word)
                new_word = new_word.replace("\\{", "{").replace("\\}", "}")
                new_arg += new_word
                newcommand += new_arg
        else:
            newcommand = command

        # Construct shlex object that will not escape any values,
        # use all values as is in argv.
        shlexer = shlex.shlex(newcommand, posix=True)
        shlexer.whitespace_split = True
        shlexer.escape = ""
        return list(shlexer) 
開發者ID:tox-dev,項目名稱:tox,代碼行數:40,代碼來源:__init__.py

示例13: split_cmd_urls

# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import list2cmdline [as 別名]
def split_cmd_urls(cmd, urls):
    _cmd = cmd + urls
    cmd_len = len(subprocess.list2cmdline(_cmd))
    if cmd_len > ARG_MAX:
        n = cmd_len // ARG_MAX + 1
        m = len(urls) // n + 1
        cmds = []
        for i in range(n):
            s = i * m
            e = s + m
            cmds.append(cmd + urls[s:e])
    else:
        cmds = [_cmd]
    return cmds 
開發者ID:ForgQi,項目名稱:bilibiliupload,代碼行數:16,代碼來源:wrap.py

示例14: join

# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import list2cmdline [as 別名]
def join(argv):
        # note that list2cmdline is specific to the windows syntax
        return subprocess.list2cmdline(argv) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:5,代碼來源:_shell_utils.py

示例15: _execute_child

# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import list2cmdline [as 別名]
def _execute_child(self, args, executable, preexec_fn, close_fds,
                       cwd, env, universal_newlines,
                       startupinfo, creationflags, shell, to_close,
                       p2cread, p2cwrite,
                       c2pread, c2pwrite,
                       errread, errwrite):
        """Code from part of _execute_child from Python 2.7 (9fbb65e)
        There are only 2 little changes concerning the construction of
        the the final string in shell mode: we preempt the creation of
        the command string when shell is True, because original function
        will try to encode unicode args which we want to avoid to be able to
        sending it as-is to ``CreateProcess``.
        """
        if not isinstance(args, subprocess.types.StringTypes):
            args = subprocess.list2cmdline(args)

        if startupinfo is None:
            startupinfo = subprocess.STARTUPINFO()
        if shell:
            startupinfo.dwFlags |= _subprocess.STARTF_USESHOWWINDOW
            startupinfo.wShowWindow = _subprocess.SW_HIDE
            comspec = os.environ.get("COMSPEC", unicode("cmd.exe"))
            args = unicode('{} /c "{}"').format(comspec, args)
            if (_subprocess.GetVersion() >= 0x80000000 or
                    os.path.basename(comspec).lower() == "command.com"):
                w9xpopen = self._find_w9xpopen()
                args = unicode('"%s" %s') % (w9xpopen, args)
                creationflags |= _subprocess.CREATE_NEW_CONSOLE

        super(Popen, self)._execute_child(args, executable,
            preexec_fn, close_fds, cwd, env, universal_newlines,
            startupinfo, creationflags, False, to_close, p2cread,
            p2cwrite, c2pread, c2pwrite, errread, errwrite) 
開發者ID:cjnaz,項目名稱:rclonesync-V2,代碼行數:35,代碼來源:win_subprocess.py


注:本文中的subprocess.list2cmdline方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。