8
|
1 #!/usr/bin/env python
|
|
2
|
|
3
|
|
4 import sys, subprocess, os
|
|
5
|
|
6 def stop_err( msg ):
|
|
7 sys.stderr.write( "%s\n" % msg )
|
|
8 sys.exit()
|
|
9
|
|
10 def __main__():
|
|
11 # Get command-line arguments
|
|
12 args = sys.argv
|
|
13 # Remove name of calling program, i.e. ./stderr_wrapper.py
|
|
14 args.pop(0)
|
|
15
|
|
16 # If there are no arguments left, we're done
|
|
17 if len(args) == 0:
|
|
18 return
|
|
19
|
|
20 # If one needs to silence stdout
|
|
21 #args.append( ">" )
|
|
22 #args.append( "/dev/null" )
|
|
23
|
|
24 cmdline = " ".join(args)
|
|
25
|
|
26
|
|
27 try:
|
|
28 # Run program
|
|
29 err_capture = open("stderr.txt", 'w')
|
|
30 proc = subprocess.Popen( args=cmdline, shell=True, stderr=err_capture, stdout=sys.stdout )
|
|
31 returncode = proc.wait()
|
|
32 err_capture.close()
|
|
33
|
|
34
|
|
35 if returncode != 0:
|
|
36 raise Exception
|
|
37
|
|
38 except Exception:
|
|
39 # Running Grinder failed: write error message to stderr
|
|
40 err_text = open("stderr.txt").readlines()
|
|
41 stop_err( "ERROR:\n" + "\n".join(err_text))
|
|
42
|
|
43
|
|
44 if __name__ == "__main__": __main__()
|