当前位置: 首页>>代码示例>>Python>>正文


Python os.exec方法代码示例

本文整理汇总了Python中os.exec方法的典型用法代码示例。如果您正苦于以下问题:Python os.exec方法的具体用法?Python os.exec怎么用?Python os.exec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在os的用法示例。


在下文中一共展示了os.exec方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_exec

# 需要导入模块: import os [as 别名]
# 或者: from os import exec [as 别名]
def test_exec(self):
        '''Test the `exec` example.'''
        filename = 'exec-{}.py'
        if six.PY2:
            filename = filename.format('py2')
            expect = {
                'SEVERITY': {'UNDEFINED': 0, 'LOW': 0, 'MEDIUM': 2, 'HIGH': 0},
                'CONFIDENCE': {'UNDEFINED': 0, 'LOW': 0, 'MEDIUM': 0,
                               'HIGH': 2}
            }
        else:
            filename = filename.format('py3')
            expect = {
                'SEVERITY': {'UNDEFINED': 0, 'LOW': 0, 'MEDIUM': 1, 'HIGH': 0},
                'CONFIDENCE': {'UNDEFINED': 0, 'LOW': 0, 'MEDIUM': 0,
                               'HIGH': 1}
            }
        self.check_example(filename, expect) 
开发者ID:PyCQA,项目名称:bandit,代码行数:20,代码来源:test_functional.py

示例2: _register_extra_bot_config

# 需要导入模块: import os [as 别名]
# 或者: from os import exec [as 别名]
def _register_extra_bot_config(content):
  """Registers the server injected extra injected.py bot_config.

  This file is called implicitly by _call_hook() and _call_hook_safe().
  """
  global _EXTRA_BOT_CONFIG
  if isinstance(content, unicode):
    # compile will throw if there's a '# coding: utf-8' line and the string is
    # in unicode. <3 python.
    content = content.encode('utf-8')
  try:
    compiled = compile(content, 'injected.py', 'exec')
    _EXTRA_BOT_CONFIG = types.ModuleType('injected')
    exec(compiled, _EXTRA_BOT_CONFIG.__dict__)
  except (SyntaxError, TypeError) as e:
    _set_quarantined(
        'handshake returned invalid injected bot_config.py: %s' % e) 
开发者ID:luci,项目名称:luci-py,代码行数:19,代码来源:bot_main.py

示例3: piped_fork_spawn

# 需要导入模块: import os [as 别名]
# 或者: from os import exec [as 别名]
def piped_fork_spawn(sh, escape, cmd, args, env, stdout, stderr):
    # spawn using fork / exec and providing a pipe for the command's
    # stdout / stderr stream
    return exec_piped_fork([sh, '-c', string.join(args)],
                           env, stdout, stderr) 
开发者ID:coin3d,项目名称:pivy,代码行数:7,代码来源:posix.py

示例4: test_os_exec

# 需要导入模块: import os [as 别名]
# 或者: from os import exec [as 别名]
def test_os_exec(self):
        '''Test for `os.exec*`.'''
        expect = {
            'SEVERITY': {'UNDEFINED': 0, 'LOW': 8, 'MEDIUM': 0, 'HIGH': 0},
            'CONFIDENCE': {'UNDEFINED': 0, 'LOW': 0, 'MEDIUM': 8, 'HIGH': 0}
        }
        self.check_example('os-exec.py', expect) 
开发者ID:PyCQA,项目名称:bandit,代码行数:9,代码来源:test_functional.py

示例5: encode_to_py3bytes_or_py2str

# 需要导入模块: import os [as 别名]
# 或者: from os import exec [as 别名]
def encode_to_py3bytes_or_py2str(s):
    """ takes anything and attempts to return a py2 string or py3 bytes.  this
    is typically used when creating command + arguments to be executed via
    os.exec* """

    fallback_encoding = "utf8"

    if IS_PY3:
        # if we're already bytes, do nothing
        if isinstance(s, bytes):
            pass
        else:
            s = str(s)
            try:
                s = bytes(s, DEFAULT_ENCODING)
            except UnicodeEncodeError:
                s = bytes(s, fallback_encoding)
    else:
        # attempt to convert the thing to unicode from the system's encoding
        try:
            s = unicode(s, DEFAULT_ENCODING)
        # if the thing is already unicode, or it's a number, it can't be
        # coerced to unicode with an encoding argument, but if we leave out
        # the encoding argument, it will convert it to a string, then to unicode
        except TypeError:
            s = unicode(s)

        # now that we have guaranteed unicode, encode to our system encoding,
        # but attempt to fall back to something
        try:
            s = s.encode(DEFAULT_ENCODING)
        except:
            s = s.encode(fallback_encoding, "replace")
    return s 
开发者ID:acaceres2176,项目名称:scylla,代码行数:36,代码来源:sh.py

示例6: compile_args

# 需要导入模块: import os [as 别名]
# 或者: from os import exec [as 别名]
def compile_args(args, kwargs, sep, prefix):
    """ takes args and kwargs, as they were passed into the command instance
    being executed with __call__, and compose them into a flat list that
    will eventually be fed into exec.  example:

    with this call:

        sh.ls("-l", "/tmp", color="never")

    this function receives

        args = ['-l', '/tmp']
        kwargs = {'color': 'never'}

    and produces

        ['-l', '/tmp', '--color=never']
        
    """
    processed_args = []
    encode = encode_to_py3bytes_or_py2str

    # aggregate positional args
    for arg in args:
        if isinstance(arg, (list, tuple)):
            if isinstance(arg, GlobResults) and not arg:
                arg = [arg.path]

            for sub_arg in arg:
                processed_args.append(encode(sub_arg))
        elif isinstance(arg, dict):
            processed_args += aggregate_keywords(arg, sep, prefix, raw=True)
        else:
            processed_args.append(encode(arg))

    # aggregate the keyword arguments
    processed_args += aggregate_keywords(kwargs, sep, prefix)

    return processed_args 
开发者ID:acaceres2176,项目名称:scylla,代码行数:41,代码来源:sh.py

示例7: run_repl

# 需要导入模块: import os [as 别名]
# 或者: from os import exec [as 别名]
def run_repl(env): # pragma: no cover
    banner = "\n>> sh v{version}\n>> https://github.com/amoffat/sh\n"

    print(banner.format(version=__version__))
    while True:
        try:
            line = raw_input("sh> ")
        except (ValueError, EOFError):
            break

        try:
            exec(compile(line, "<dummy>", "single"), env, env)
        except SystemExit:
            break
        except:
            print(traceback.format_exc())

    # cleans up our last line
    print("")




# this is a thin wrapper around THIS module (we patch sys.modules[__name__]).
# this is in the case that the user does a "from sh import whatever"
# in other words, they only want to import certain programs, not the whole
# system PATH worth of commands.  in this case, we just proxy the
# import lookup to our Environment class 
开发者ID:acaceres2176,项目名称:scylla,代码行数:30,代码来源:sh.py

示例8: exec_piped_fork

# 需要导入模块: import os [as 别名]
# 或者: from os import exec [as 别名]
def exec_piped_fork(l, env, stdout, stderr):
    # spawn using fork / exec and providing a pipe for the command's
    # stdout / stderr stream
    if stdout != stderr:
        (rFdOut, wFdOut) = os.pipe()
        (rFdErr, wFdErr) = os.pipe()
    else:
        (rFdOut, wFdOut) = os.pipe()
        rFdErr = rFdOut
        wFdErr = wFdOut
    # do the fork
    pid = os.fork()
    if not pid:
        # Child process
        os.close( rFdOut )
        if rFdOut != rFdErr:
            os.close( rFdErr )
        os.dup2( wFdOut, 1 ) # is there some symbolic way to do that ?
        os.dup2( wFdErr, 2 )
        os.close( wFdOut )
        if stdout != stderr:
            os.close( wFdErr )
        exitval = 127
        try:
            os.execvpe(l[0], l, env)
        except OSError, e:
            exitval = exitvalmap.get(e[0], e[0])
            stderr.write("scons: %s: %s\n" % (l[0], e[1]))
        os._exit(exitval) 
开发者ID:Autodesk,项目名称:sitoa,代码行数:31,代码来源:posix.py

示例9: piped_fork_spawn

# 需要导入模块: import os [as 别名]
# 或者: from os import exec [as 别名]
def piped_fork_spawn(sh, escape, cmd, args, env, stdout, stderr):
    # spawn using fork / exec and providing a pipe for the command's
    # stdout / stderr stream
    return exec_piped_fork([sh, '-c', ' '.join(args)],
                           env, stdout, stderr) 
开发者ID:Autodesk,项目名称:sitoa,代码行数:7,代码来源:posix.py

示例10: exec_piped_fork

# 需要导入模块: import os [as 别名]
# 或者: from os import exec [as 别名]
def exec_piped_fork(l, env, stdout, stderr):
    # spawn using fork / exec and providing a pipe for the command's
    # stdout / stderr stream
    if stdout != stderr:
        (rFdOut, wFdOut) = os.pipe()
        (rFdErr, wFdErr) = os.pipe()
    else:
        (rFdOut, wFdOut) = os.pipe()
        rFdErr = rFdOut
        wFdErr = wFdOut
    # do the fork
    pid = os.fork()
    if not pid:
        # Child process
        os.close( rFdOut )
        if rFdOut != rFdErr:
            os.close( rFdErr )
        os.dup2( wFdOut, 1 ) # is there some symbolic way to do that ?
        os.dup2( wFdErr, 2 )
        os.close( wFdOut )
        if stdout != stderr:
            os.close( wFdErr )
        exitval = 127
        try:
            os.execvpe(l[0], l, env)
        except OSError as e:
            exitval = exitvalmap.get(e[0], e[0])
            stderr.write("scons: %s: %s\n" % (l[0], e[1]))
        os._exit(exitval)
    else:
        # Parent process
        pid, stat = os.waitpid(pid, 0)
        os.close( wFdOut )
        if stdout != stderr:
            os.close( wFdErr )
        childOut = os.fdopen( rFdOut )
        if stdout != stderr:
            childErr = os.fdopen( rFdErr )
        else:
            childErr = childOut
        process_cmd_output(childOut, childErr, stdout, stderr)
        os.close( rFdOut )
        if stdout != stderr:
            os.close( rFdErr )
        if stat & 0xff:
            return stat | 0x80
        return stat >> 8 
开发者ID:coin3d,项目名称:pivy,代码行数:49,代码来源:posix.py

示例11: generate

# 需要导入模块: import os [as 别名]
# 或者: from os import exec [as 别名]
def generate(env):
    # If os.spawnvpe() exists, we use it to spawn commands.  Otherwise
    # if the env utility exists, we use os.system() to spawn commands,
    # finally we fall back on os.fork()/os.exec().  
    #
    # os.spawnvpe() is prefered because it is the most efficient.  But
    # for Python versions without it, os.system() is prefered because it
    # is claimed that it works better with threads (i.e. -j) and is more
    # efficient than forking Python.
    #
    # NB: Other people on the scons-users mailing list have claimed that
    # os.fork()/os.exec() works better than os.system().  There may just
    # not be a default that works best for all users.

    if 'spawnvpe' in os.__dict__:
        spawn = spawnvpe_spawn
    elif env.Detect('env'):
        spawn = env_spawn
    else:
        spawn = fork_spawn

    if env.Detect('env'):
        pspawn = piped_env_spawn
    else:
        pspawn = piped_fork_spawn

    if 'ENV' not in env:
        env['ENV']        = {}
    env['ENV']['PATH']    = '/usr/local/bin:/opt/bin:/bin:/usr/bin'
    env['OBJPREFIX']      = ''
    env['OBJSUFFIX']      = '.o'
    env['SHOBJPREFIX']    = '$OBJPREFIX'
    env['SHOBJSUFFIX']    = '$OBJSUFFIX'
    env['PROGPREFIX']     = ''
    env['PROGSUFFIX']     = ''
    env['LIBPREFIX']      = 'lib'
    env['LIBSUFFIX']      = '.a'
    env['SHLIBPREFIX']    = '$LIBPREFIX'
    env['SHLIBSUFFIX']    = '.so'
    env['LIBPREFIXES']    = [ '$LIBPREFIX' ]
    env['LIBSUFFIXES']    = [ '$LIBSUFFIX', '$SHLIBSUFFIX' ]
    env['PSPAWN']         = pspawn
    env['SPAWN']          = spawn
    env['SHELL']          = 'sh'
    env['ESCAPE']         = escape
    env['TEMPFILE']       = TempFileMunge
    env['TEMPFILEPREFIX'] = '@'
    #Based on LINUX: ARG_MAX=ARG_MAX=131072 - 3000 for environment expansion
    #Note: specific platforms might rise or lower this value
    env['MAXLINELENGTH']  = 128072

    # This platform supports RPATH specifications.
    env['__RPATH'] = '$_RPATH'

# Local Variables:
# tab-width:4
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=4 shiftwidth=4: 
开发者ID:coin3d,项目名称:pivy,代码行数:61,代码来源:posix.py

示例12: _bot_restart

# 需要导入模块: import os [as 别名]
# 或者: from os import exec [as 别名]
def _bot_restart(botobj, message, filepath=None):
  """Restarts the bot process, optionally in a new file.

  The function will return if the new bot code is not valid.
  """
  filepath = filepath or THIS_FILE
  s = fs.stat(filepath)
  logging.info('Restarting to %s; %d bytes.', filepath, s.st_size)
  sys.stdout.flush()
  sys.stderr.flush()

  proc = _Popen(botobj, [sys.executable, filepath, 'is_fine'])
  output, _ = proc.communicate()
  if proc.returncode:
    botobj.post_error(
        'New bot code is bad: proc exit = %s. stdout:\n%s' %
        (proc.returncode, output))
    if sys.platform == 'win32' and proc.returncode == -1073741502:
      # STATUS_DLL_INIT_FAILED generally means that something bad happened, and
      # a reboot magically clears things out. :(
      botobj.host_reboot(
          'Working around STATUS_DLL_INIT_FAILED when restarting the bot')
    return

  botobj.post_event('bot_shutdown', 'About to restart: %s' % message)

  # Sleep a bit to make sure new bot process connects to a GAE instance with
  # the fresh bot group config cache (it gets refreshed each second). This makes
  # sure the bot doesn't accidentally pick up the old config after restarting
  # and connecting to an instance with a stale cache.
  time.sleep(2)

  # Don't forget to release the singleton before restarting itself.
  SINGLETON.release()

  # Do not call on_bot_shutdown.
  # On OSX, launchd will be unhappy if we quit so the old code bot process has
  # to outlive the new code child process. Launchd really wants the main process
  # to survive, and it'll restart it if it disappears. os.exec*() replaces the
  # process so this is fine.
  ret = common.exec_python([filepath, 'start_slave', '--survive'])
  if ret in (1073807364, -1073741510):
    # 1073807364 is returned when the process is killed due to shutdown. No need
    # to alert anyone in that case.
    # -1073741510 is returned when rebooting too. This can happen when the
    # parent code was running the old version and gets confused and decided to
    # poll again.
    # In any case, zap out the error code.
    ret = 0
  elif ret:
    botobj.post_error('Bot failed to respawn after update: %s' % ret)
  sys.exit(ret) 
开发者ID:luci,项目名称:luci-py,代码行数:54,代码来源:bot_main.py


注:本文中的os.exec方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。