提交 0a431120 authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Add documenation for the new functions.

上级 80ebe9c3
...@@ -4,7 +4,9 @@ import subprocess ...@@ -4,7 +4,9 @@ import subprocess
def subprocess_Popen(command, **params): def subprocess_Popen(command, **params):
""" """
Utility function to work around windows behavior that open windows Utility function to work around windows behavior that open windows.
:see: call_subprocess_Popen and output_subprocess_Popen
""" """
startupinfo = None startupinfo = None
if os.name == 'nt': if os.name == 'nt':
...@@ -38,6 +40,10 @@ def subprocess_Popen(command, **params): ...@@ -38,6 +40,10 @@ def subprocess_Popen(command, **params):
return proc return proc
def call_subprocess_Popen(command, **params): def call_subprocess_Popen(command, **params):
"""
Calls subprocess_Popen and discards the output, returning only the
exit code.
"""
if 'stdout' in params or 'stderr' in params: if 'stdout' in params or 'stderr' in params:
raise TypeError("don't use stderr or stdout with call_subprocess_Popen") raise TypeError("don't use stderr or stdout with call_subprocess_Popen")
null = open(os.devnull, 'wb') null = open(os.devnull, 'wb')
...@@ -51,6 +57,10 @@ def call_subprocess_Popen(command, **params): ...@@ -51,6 +57,10 @@ def call_subprocess_Popen(command, **params):
return p.returncode return p.returncode
def output_subprocess_Popen(command, **params): def output_subprocess_Popen(command, **params):
"""
Calls subprocess_Popen, returning the output, error and exit code
in a tuple.
"""
if 'stdout' in params or 'stderr' in params: if 'stdout' in params or 'stderr' in params:
raise TypeError("don't use stderr or stdout with output_subprocess_Popen") raise TypeError("don't use stderr or stdout with output_subprocess_Popen")
# stdin to devnull is a workaround for a crash in a weird Windows # stdin to devnull is a workaround for a crash in a weird Windows
...@@ -61,5 +71,7 @@ def output_subprocess_Popen(command, **params): ...@@ -61,5 +71,7 @@ def output_subprocess_Popen(command, **params):
params['stdout'] = subprocess.PIPE params['stdout'] = subprocess.PIPE
params['stderr'] = subprocess.PIPE params['stderr'] = subprocess.PIPE
p = subprocess_Popen(command, **params) p = subprocess_Popen(command, **params)
# we need to use communicate to make sure we don't deadlock around
# the stdour/stderr pipe.
out = p.communicate() out = p.communicate()
return out + (p.returncode,) return out + (p.returncode,)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论