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