本文整理汇总了Python中subprocess32.PIPE属性的典型用法代码示例。如果您正苦于以下问题:Python subprocess32.PIPE属性的具体用法?Python subprocess32.PIPE怎么用?Python subprocess32.PIPE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类subprocess32
的用法示例。
在下文中一共展示了subprocess32.PIPE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: exec_command
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import PIPE [as 别名]
def exec_command(cmd, args, cwd, timeout=None):
"""
Executes shell command inside @repo_path
returns exec code
"""
pipe = None
try:
env = os.environ
env["PATH"] = env["NDK_TOOLCHAIN"] + "/bin:" + env["PATH"]
pipe = Popen(args, stdin=PIPE, stdout=PIPE, cwd=cwd, env=env)
stdout, error = pipe.communicate(timeout=timeout) if (timeout and timeout > 0) else pipe.communicate()
logger.debug("stdout: %s", stdout)
return pipe.returncode
except TimeoutExpired as te:
pipe.terminate()
logger.error("%s timed out: %s", cmd, str(te))
return 0
except Exception as e:
logger.error("%s subprocess failed: %s", cmd, str(e))
return -1
示例2: execute
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import PIPE [as 别名]
def execute(cls, cmd, stdin_payload=None, **kwargs):
"""Execute a command via subprocess.Popen and returns the stdio.
:param string|list cmd: A list or string representing the command to run.
:param string stdin_payload: A string representing the stdin payload, if any, to send.
:param **kwargs: Additional kwargs to pass through to subprocess.Popen.
:return: A tuple of strings representing (stdout, stderr), pre-decoded for utf-8.
:raises: `Executor.ExecutableNotFound` when the executable requested to run does not exist.
`Executor.NonZeroExit` when the execution fails with a non-zero exit code.
"""
process = cls.open_process(cmd=cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
**kwargs)
stdout_raw, stderr_raw = process.communicate(input=stdin_payload)
# N.B. In cases where `stdout` or `stderr` is passed as parameters, these can be None.
stdout = stdout_raw.decode('utf-8') if stdout_raw is not None else stdout_raw
stderr = stderr_raw.decode('utf-8') if stderr_raw is not None else stderr_raw
if process.returncode != 0:
raise cls.NonZeroExit(cmd, process.returncode, stdout, stderr)
return stdout, stderr
示例3: command
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import PIPE [as 别名]
def command(cmd, *arguments, **options):
close_fds = options.get('close_fds', True)
cwd = options.get('cwd', None)
shell = options.get('shell', False)
env = options.get('env', None)
if env is not None:
env = dict(os.environ, **env)
stdin = options.get('stdin', None)
subproc = subprocess32.Popen([cmd] + list(arguments),
close_fds=close_fds,
shell=shell,
cwd=cwd,
env=env,
stdin=subprocess32.PIPE,
stdout=subprocess32.PIPE,
stderr=subprocess32.PIPE, )
out, err = subproc.communicate(input=stdin)
subproc.wait()
return (subproc.returncode, out, err)
示例4: subproc
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import PIPE [as 别名]
def subproc(script, cwd=None):
subproc = subprocess32.Popen(['sh'],
close_fds=True,
cwd=cwd,
stdin=subprocess32.PIPE,
stdout=subprocess32.PIPE,
stderr=subprocess32.PIPE)
out, err = subproc.communicate(script)
subproc.wait()
if subproc.returncode != 0:
print out
print err
return (subproc.returncode, out, err)
示例5: open_process
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import PIPE [as 别名]
def open_process(command, cwd=None, shell=True, _popen_lock=threading.Lock()):
kwargs = {
"shell": shell,
"stdout": subprocess.PIPE,
"stderr": subprocess.STDOUT,
"stdin": subprocess.PIPE,
"bufsize": 1, # Line buffered
"universal_newlines": True,
}
if cwd is not None:
kwargs["cwd"] = cwd
# Prevent signal propagation from parent process
try:
# Windows
kwargs["creationflags"] = subprocess.CREATE_NEW_PROCESS_GROUP
except AttributeError:
# Unix
kwargs["preexec_fn"] = os.setpgrp
with _popen_lock: # Work around Python 2 Popen race condition
return subprocess.Popen(command, **kwargs)
示例6: xvfb_supports_listen
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import PIPE [as 别名]
def xvfb_supports_listen():
"""Determine whether the '-listen' option is supported by Xvfb."""
p = subprocess.Popen(
['Xvfb', '-listen', 'TCP', '-__sentinel_parameter__'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
p.wait()
_, stderr = p.communicate()
match = re.search(
br'^Unrecognized option: (?P<option>.*)$',
stderr,
flags=re.MULTILINE,
).groupdict()
unrecognized_option = match['option']
return unrecognized_option != b'-listen'
示例7: check_output
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import PIPE [as 别名]
def check_output(*popenargs, **kwargs):
"""Run command with arguments and return its output (both stdout and stderr) as a byte string.
If the exit code was non-zero it raises a CalledProcessWithOutputError.
"""
if 'stdout' in kwargs:
raise ValueError('stdout argument not allowed, it will be overridden.')
if 'stderr' in kwargs:
raise ValueError('stderr argument not allowed, it will be overridden.')
process = subprocess.Popen(
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
*popenargs, **kwargs)
output, err = process.communicate()
retcode = process.poll()
if retcode:
cmd = kwargs.get("args")
if cmd is None:
cmd = popenargs[0]
raise CalledProcessWithOutputError(retcode, cmd, output, err)
return output, err
示例8: test_stdin_stdout
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import PIPE [as 别名]
def test_stdin_stdout(self):
proc = subprocess32.Popen(
(sys.executable, '-m', 'pykit.p3json.tool'),
stdin=subprocess32.PIPE, stdout=subprocess32.PIPE)
out, err = proc.communicate(self.data.encode())
self._assert_expected(out, linemode=True)
self.assertEqual(err, None)
示例9: page
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import PIPE [as 别名]
def page(lines, max_lines=10, control_char=True, pager=('less',)):
if len(lines) > max_lines:
pp = {'stdin': subprocess32.PIPE,
'stdout': None,
'stderr': None}
cmd_pager = list(pager)
if control_char:
if pager == ('less', ):
cmd_pager += ['-r']
subproc = subprocess32.Popen(cmd_pager,
close_fds=True,
cwd='./',
**pp)
try:
out, err = subproc.communicate('\n'.join(lines))
except IOError as e:
if e[0] == errno.EPIPE:
pass
else:
raise
subproc.wait()
else:
os.write(1, '\n'.join(lines) + "\n")
示例10: start
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import PIPE [as 别名]
def start(self, args):
cmd = self._get_cmd(args)
self.proc = subprocess.Popen(cmd, stderr=subprocess.STDOUT,
stdout=subprocess.PIPE, preexec_fn=os.setsid,
shell=self.shell)
try:
args = self._ready()
self.msg_ready(args)
except ProcessException, e:
# Ignore errors if process is being killed
if not self.killing:
self._set_error(str(e))
示例11: __init__
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import PIPE [as 别名]
def __init__(self, args):
self.args = args
self.process = subprocess32.Popen(
args,
stdin=subprocess32.PIPE,
stdout=subprocess32.PIPE,
stderr=subprocess32.PIPE
)
self.err = None
示例12: __init__
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import PIPE [as 别名]
def __init__(self, device_url, bundle_id=None):
DeviceMixin.__init__(self)
self.__device_url = device_url
self.__scale = None
self._wda = wda.Client(device_url)
self._session = None
self._bundle_id = None
if bundle_id:
self.start_app(bundle_id)
# ioskit.Device.__init__(self, udid)
# # xcodebuild -project -scheme WebDriverAgentRunner -destination "id=1002c0174e481a651d71e3d9a89bd6f90d253446" test
# # Test Case '-[UITestingUITests testRunner]' started.
# xproj_dir = os.getenv('WEBDRIVERAGENT_DIR')
# if not xproj_dir:
# raise RuntimeError("env-var WEBDRIVERAGENT_DIR need to be set")
# proc = self._xcproc = subprocess.Popen(['/usr/bin/xcodebuild',
# '-project', 'WebDriverAgent.xcodeproj',
# '-scheme', 'WebDriverAgentRunner',
# '-destination', 'id='+self.udid, 'test'],
# stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=xproj_dir, bufsize=1, universal_newlines=True)
# for line in iter(proc.stdout.readline, b""):
# print 'STDOUT:', line.strip()
# if 'TEST FAILED' in line:
# raise RuntimeError("webdriver start test failed, maybe need to unlock the keychain, try\n" +
# '$ security unlock-keychain ~/Library/Keychains/login.keychain')
# elif "Successfully wrote Manifest cache" in line:
# print 'GOOD ^_^, wait 5s'
# time.sleep(5.0)
# break
示例13: _init_instruments
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import PIPE [as 别名]
def _init_instruments(self, bundle_id):
self._bootstrap = os.path.join(__dir__, 'bootstrap.sh')
self._bundle_id = bundle_id
self._env.update({'UDID': self.udid, 'BUNDLE_ID': self._bundle_id})
# 1. remove pipe
# subprocess.check_output([self._bootstrap, 'reset'], env=self._env)
# 2. start instruments
self._proc = subprocess.Popen([self._bootstrap, 'instruments'], env=self._env, stdout=subprocess.PIPE)
self.sleep(5.0)
self._wait_instruments()
示例14: raw_cmd
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import PIPE [as 别名]
def raw_cmd(self, *args, **kwargs):
'''adb command. return the subprocess.Popen object.'''
cmds = [self.adb_path()] + self._host_port_args + list(args)
kwargs['stdout'] = kwargs.get('stdout', subprocess.PIPE)
kwargs['stderr'] = kwargs.get('stderr', subprocess.PIPE)
# if os.name != "nt":
# cmd_line = [" ".join(cmd_line)]
cmds = [strutils.decode(v) for v in cmds]
return subprocess.Popen(cmds, **kwargs)
示例15: start_app
# 需要导入模块: import subprocess32 [as 别名]
# 或者: from subprocess32 import PIPE [as 别名]
def start_app(self, bundle_id):
'''
Start app by bundle_id
Args:
- bundle_id(string): ex com.netease.my
Returns:
idevicedebug subprocess instance
'''
idevicedebug = must_look_exec('idevicedebug')
# run in background
kwargs = {'stdout': subprocess.PIPE, 'stderr': subprocess.PIPE}
if sys.platform != 'darwin':
kwargs['close_fds'] = True
return subprocess.Popen([idevicedebug, "--udid", self.udid, 'run', bundle_id], **kwargs)