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


Python os.spawn方法代碼示例

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


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

示例1: runProcess

# 需要導入模塊: import os [as 別名]
# 或者: from os import spawn [as 別名]
def runProcess(cmd, *args):
    """Run `cmd` (which is searched for in the executable path) with `args` and
    return the exit status.

    In general (unless you know what you're doing) use::

     runProcess('program', filename)

    rather than::

     os.system('program %s' % filename)

    because the latter will not work as expected if `filename` contains
    spaces or shell-metacharacters.

    If you need more fine-grained control look at ``os.spawn*``.
    """
    from os import spawnvp, P_WAIT
    return spawnvp(P_WAIT, cmd, (cmd,) + args)


#FIXME; check latest word on this... 
開發者ID:hello-sea,項目名稱:DeepLearning_Wavelet-LSTM,代碼行數:24,代碼來源:awmstools.py

示例2: _exec_command

# 需要導入模塊: import os [as 別名]
# 或者: from os import spawn [as 別名]
def _exec_command(command, use_shell=None, use_tee = None, **env):
    """
    Internal workhorse for exec_command().
    """
    if use_shell is None:
        use_shell = os.name=='posix'
    if use_tee is None:
        use_tee = os.name=='posix'

    if os.name == 'posix' and use_shell:
        # On POSIX, subprocess always uses /bin/sh, override
        sh = os.environ.get('SHELL', '/bin/sh')
        if is_sequence(command):
            command = [sh, '-c', ' '.join(command)]
        else:
            command = [sh, '-c', command]
        use_shell = False

    elif os.name == 'nt' and is_sequence(command):
        # On Windows, join the string for CreateProcess() ourselves as
        # subprocess does it a bit differently
        command = ' '.join(_quote_arg(arg) for arg in command)

    # Inherit environment by default
    env = env or None
    try:
        proc = subprocess.Popen(command, shell=use_shell, env=env,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.STDOUT,
                                universal_newlines=True)
    except EnvironmentError:
        # Return 127, as os.spawn*() and /bin/sh do
        return 127, ''
    text, err = proc.communicate()
    # Another historical oddity
    if text[-1:] == '\n':
        text = text[:-1]
    if use_tee and text:
        print(text)
    return proc.returncode, text 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:42,代碼來源:exec_command.py

示例3: test_os_spawn

# 需要導入模塊: import os [as 別名]
# 或者: from os import spawn [as 別名]
def test_os_spawn(self):
        '''Test for `os.spawn*`.'''
        expect = {
            'SEVERITY': {'UNDEFINED': 0, 'LOW': 8, 'MEDIUM': 0, 'HIGH': 0},
            'CONFIDENCE': {'UNDEFINED': 0, 'LOW': 0, 'MEDIUM': 8, 'HIGH': 0}
        }
        self.check_example('os-spawn.py', expect) 
開發者ID:PyCQA,項目名稱:bandit,代碼行數:9,代碼來源:test_functional.py

示例4: _setup_platform

# 需要導入模塊: import os [as 別名]
# 或者: from os import spawn [as 別名]
def _setup_platform():
        """Setup the shell command and the command line argument escape
        function depending on the underlying platform
        """
        global _cmdline2listimpl, _escape_args, _shell_command

        if os._name in _win_oses:
            _cmdline2listimpl = _cmdline2list
            _escape_args = lambda args: [list2cmdline([arg]) for arg in args]
        else:
            _cmdline2listimpl = lambda args: [args]
            _escape_args = lambda args: args

        for shell_command in os._get_shell_commands():
            executable = shell_command[0]
            if not os.path.isabs(executable):
                import distutils.spawn
                executable = distutils.spawn.find_executable(executable)
            if not executable or not os.path.exists(executable):
                continue
            shell_command[0] = executable
            _shell_command = shell_command
            return

        if not _shell_command:
            import warnings
            warnings.warn('Unable to determine _shell_command for '
                          'underlying os: %s' % os._name, RuntimeWarning, 3) 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:30,代碼來源:subprocess.py

示例5: _exec_command

# 需要導入模塊: import os [as 別名]
# 或者: from os import spawn [as 別名]
def _exec_command(command, use_shell=None, use_tee = None, **env):
    """
    Internal workhorse for exec_command().
    """
    if use_shell is None:
        use_shell = os.name=='posix'
    if use_tee is None:
        use_tee = os.name=='posix'

    if os.name == 'posix' and use_shell:
        # On POSIX, subprocess always uses /bin/sh, override
        sh = os.environ.get('SHELL', '/bin/sh')
        if is_sequence(command):
            command = [sh, '-c', ' '.join(command)]
        else:
            command = [sh, '-c', command]
        use_shell = False

    elif os.name == 'nt' and is_sequence(command):
        # On Windows, join the string for CreateProcess() ourselves as
        # subprocess does it a bit differently
        command = ' '.join(_quote_arg(arg) for arg in command)

    # Inherit environment by default
    env = env or None
    try:
        # universal_newlines is set to False so that communicate()
        # will return bytes. We need to decode the output ourselves
        # so that Python will not raise a UnicodeDecodeError when
        # it encounters an invalid character; rather, we simply replace it
        proc = subprocess.Popen(command, shell=use_shell, env=env,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.STDOUT,
                                universal_newlines=False)
    except EnvironmentError:
        # Return 127, as os.spawn*() and /bin/sh do
        return 127, ''

    text, err = proc.communicate()
    mylocale = locale.getpreferredencoding(False)
    if mylocale is None:
        mylocale = 'ascii'
    text = text.decode(mylocale, errors='replace')
    text = text.replace('\r\n', '\n')
    # Another historical oddity
    if text[-1:] == '\n':
        text = text[:-1]

    # stdio uses bytes in python 2, so to avoid issues, we simply
    # remove all non-ascii characters
    if sys.version_info < (3, 0):
        text = text.encode('ascii', errors='replace')

    if use_tee and text:
        print(text)
    return proc.returncode, text 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:58,代碼來源:exec_command.py

示例6: _exec_command

# 需要導入模塊: import os [as 別名]
# 或者: from os import spawn [as 別名]
def _exec_command(command, use_shell=None, use_tee = None, **env):
    """
    Internal workhorse for exec_command().
    """
    if use_shell is None:
        use_shell = os.name=='posix'
    if use_tee is None:
        use_tee = os.name=='posix'

    if os.name == 'posix' and use_shell:
        # On POSIX, subprocess always uses /bin/sh, override
        sh = os.environ.get('SHELL', '/bin/sh')
        if is_sequence(command):
            command = [sh, '-c', ' '.join(command)]
        else:
            command = [sh, '-c', command]
        use_shell = False

    elif os.name == 'nt' and is_sequence(command):
        # On Windows, join the string for CreateProcess() ourselves as
        # subprocess does it a bit differently
        command = ' '.join(_quote_arg(arg) for arg in command)

    # Inherit environment by default
    env = env or None
    try:
        # universal_newlines is set to False so that communicate()
        # will return bytes. We need to decode the output ourselves
        # so that Python will not raise a UnicodeDecodeError when
        # it encounters an invalid character; rather, we simply replace it
        proc = subprocess.Popen(command, shell=use_shell, env=env,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.STDOUT,
                                universal_newlines=False)
    except EnvironmentError:
        # Return 127, as os.spawn*() and /bin/sh do
        return 127, ''

    text, err = proc.communicate()
    text = text.decode(locale.getpreferredencoding(False),
                       errors='replace')

    text = text.replace('\r\n', '\n')
    # Another historical oddity
    if text[-1:] == '\n':
        text = text[:-1]

    # stdio uses bytes in python 2, so to avoid issues, we simply
    # remove all non-ascii characters
    if sys.version_info < (3, 0):
        text = text.encode('ascii', errors='replace')

    if use_tee and text:
        print(text)
    return proc.returncode, text 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:57,代碼來源:exec_command.py


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