diff options
Diffstat (limited to 'utils/lit/lit/util.py')
-rw-r--r-- | utils/lit/lit/util.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/utils/lit/lit/util.py b/utils/lit/lit/util.py index d7d6d7f163..ce26f06d6d 100644 --- a/utils/lit/lit/util.py +++ b/utils/lit/lit/util.py @@ -2,6 +2,8 @@ import errno import itertools import math import os +import platform +import signal import subprocess import sys @@ -138,3 +140,20 @@ def printHistogram(items, title = 'Items'): pDigits, pfDigits, i*barH, pDigits, pfDigits, (i+1)*barH, '*'*w, ' '*(barW-w), cDigits, len(row), cDigits, len(items))) +# Close extra file handles on UNIX (on Windows this cannot be done while +# also redirecting input). +kUseCloseFDs = not (platform.system() == 'Windows') +def executeCommand(command, cwd=None, env=None): + p = subprocess.Popen(command, cwd=cwd, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + env=env, close_fds=kUseCloseFDs) + out,err = p.communicate() + exitCode = p.wait() + + # Detect Ctrl-C in subprocess. + if exitCode == -signal.SIGINT: + raise KeyboardInterrupt + + return out, err, exitCode |