本文整理匯總了Python中subprocess32.Popen.__init__方法的典型用法代碼示例。如果您正苦於以下問題:Python Popen.__init__方法的具體用法?Python Popen.__init__怎麽用?Python Popen.__init__使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類subprocess32.Popen
的用法示例。
在下文中一共展示了Popen.__init__方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from subprocess32 import Popen [as 別名]
# 或者: from subprocess32.Popen import __init__ [as 別名]
def __init__(self, cmd, cwd=None, env=None, flags=None,
stdin=PIPE, stdout=PIPE, stderr=PIPE,
universal_newlines=True):
"""Create a child process.
"cmd" is the command to run, either a list of arguments or a string.
"cwd" is a working directory in which to start the child process.
"env" is an environment dictionary for the child.
"flags" are system-specific process creation flags. On Windows
this can be a bitwise-OR of any of the win32process.CREATE_*
constants (Note: win32process.CREATE_NEW_PROCESS_GROUP is always
OR'd in). On Unix, this is currently ignored.
"stdin", "stdout", "stderr" can be used to specify file objects
to handle read (stdout/stderr) and write (stdin) events from/to
the child. By default a file handle will be created for each
io channel automatically, unless set explicitly to None. When set
to None, the parent io handles will be used, which can mean the
output is redirected to Komodo's log files.
"universal_newlines": On by default (the opposite of subprocess).
"""
self._child_created = False
self.__use_killpg = False
auto_piped_stdin = False
preexec_fn = None
shell = False
if not isinstance(cmd, (list, tuple)):
# The cmd is the already formatted, ready for the shell. Otherwise
# subprocess.Popen will treat this as simply one command with
# no arguments, resulting in an unknown command.
shell = True
if sys.platform.startswith("win"):
# On Windows, cmd requires some special handling of multiple quoted
# arguments, as this is what cmd will do:
# See if the first character is a quote character and if so,
# strip the leading character and remove the last quote character
# on the command line, preserving any text after the last quote
# character.
if cmd and shell and cmd.count('"') > 2:
if not cmd.startswith('""') or not cmd.endswith('""'):
# Needs to be a re-quoted with additional double quotes.
# http://bugs.activestate.com/show_bug.cgi?id=75467
cmd = '"%s"' % (cmd, )
# XXX - subprocess needs to be updated to use the wide string API.
# subprocess uses a Windows API that does not accept unicode, so
# we need to convert all the environment variables to strings
# before we make the call. Temporary fix to bug:
# http://bugs.activestate.com/show_bug.cgi?id=72311
if env:
encoding = sys.getfilesystemencoding()
_enc_env = {}
for key, value in env.items():
try:
_enc_env[key.encode(encoding)] = value.encode(encoding)
except (UnicodeEncodeError, UnicodeDecodeError):
# Could not encode it, warn we are dropping it.
log.warn("Could not encode environment variable %r "
"so removing it", key)
env = _enc_env
if flags is None:
flags = CREATE_NO_WINDOW
# If we don't have standard handles to pass to the child process
# (e.g. we don't have a console app), then
# `subprocess.GetStdHandle(...)` will return None. `subprocess.py`
# handles that (http://bugs.python.org/issue1124861)
#
# However, if Komodo is started from the command line, then
# the shell's stdin handle is inherited, i.e. in subprocess.py:
# p2cread = GetStdHandle(STD_INPUT_HANDLE) # p2cread == 3
# A few lines later this leads to:
# Traceback (most recent call last):
# ...
# File "...\lib\mozilla\python\komodo\process.py", line 130, in __init__
# creationflags=flags)
# File "...\lib\python\lib\subprocess.py", line 588, in __init__
# errread, errwrite) = self._get_handles(stdin, stdout, stderr)
# File "...\lib\python\lib\subprocess.py", line 709, in _get_handles
# p2cread = self._make_inheritable(p2cread)
# File "...\lib\python\lib\subprocess.py", line 773, in _make_inheritable
# DUPLICATE_SAME_ACCESS)
# WindowsError: [Error 6] The handle is invalid
#
# I suspect this indicates that the stdin handle inherited by
# the subsystem:windows komodo.exe process is invalid -- perhaps
# because of mis-used of the Windows API for passing that handle
# through. The same error can be demonstrated in PythonWin:
# from _subprocess import *
# from subprocess import *
# h = GetStdHandle(STD_INPUT_HANDLE)
# p = Popen("python -c '1'")
# p._make_interitable(h)
#
# I don't understand why the inherited stdin is invalid for
# `DuplicateHandle`, but here is how we are working around this:
# If we detect the condition where this can fail, then work around
# it by setting the handle to `subprocess.PIPE`, resulting in
# a different and workable code path.
if self._needToHackAroundStdHandles() \
#.........這裏部分代碼省略.........
示例2: __init__
# 需要導入模塊: from subprocess32 import Popen [as 別名]
# 或者: from subprocess32.Popen import __init__ [as 別名]
def __init__(self, cargs, *args, **kwargs):
Popen.__init__(self, cargs, *args, start_new_session=True)
self.args = cargs