Add a utility script that executes an inferior process tucking its output away somewhere safe, and not letting error messages escape

This has potential to be useful in build automation environments

llvm-svn: 226300
This commit is contained in:
Enrico Granata 2015-01-16 18:59:54 +00:00
parent ef5c9503e3
commit baa15585ca
1 changed files with 47 additions and 0 deletions

47
lldb/scripts/shush Executable file
View File

@ -0,0 +1,47 @@
#!/usr/bin/env python
import sys
import subprocess
import tempfile
import time
def command():
return ' '.join(sys.argv[1:])
def tmpfile(suffix=None):
return tempfile.NamedTemporaryFile(prefix='shush', suffix=suffix, delete=False)
def launch(sin=None, sout=None, serr=None):
class Process(object):
def __init__(self, p, i, o, e):
self.p = p
self.stdin = i
self.stdout = o
self.stderr = e
def poll(self):
self.returncode = self.p.poll()
return self.returncode
return Process(subprocess.Popen(command(), shell=True, stdin=sin, stdout=sout, stderr=serr), sin, sout, serr)
def wait(p):
while p.poll() is None:
time.sleep(5)
print "still running..." # fool Xcode into thinking that I am doing something...
return p
def exit(p):
code = p.returncode
if code != 0:
print "error: sucks to be you"
print ("error: shushed process failed - go check %s and %s for details" % (p.stdout.name, p.stderr.name))
sys.exit(code)
def main():
out = tmpfile(suffix="stdout")
err = tmpfile(suffix="stderr")
p = wait(launch(sout=out, serr=err))
exit(p)
main()