From fb4a49b5700db5de9dea1e19e0026e7b296d2968 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 9 Nov 2012 08:59:58 -0800 Subject: [PATCH] add win32.capture_output() --- edbob/win32.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/edbob/win32.py b/edbob/win32.py index e74e650..96a76bd 100644 --- a/edbob/win32.py +++ b/edbob/win32.py @@ -163,6 +163,20 @@ def RegDeleteTree(key, subkey): pass +def capture_output(command): + """ + Runs ``command`` and returns any output it produces. + """ + + # We *need* to pipe ``stdout`` because that's how we capture the output of + # the ``hg`` command. However, we must pipe *all* handles in order to + # prevent issues when running as a GUI but *from* the Windows console. + # See also: http://bugs.python.org/issue3905 + kwargs = dict(stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + output = subprocess.Popen(command, **kwargs).communicate()[0] + return output + + def delayed_auto_start_service(name): """ Configures the Windows service named ``name`` such that its startup type is