forked from OSchip/llvm-project
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:
parent
ef5c9503e3
commit
baa15585ca
|
@ -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()
|
Loading…
Reference in New Issue