Mercurial > repos > gkumar09 > trinityrnaseq_protocol
changeset 8:e40d92918044 draft
Uploaded
author | gkumar09 |
---|---|
date | Wed, 23 Sep 2015 15:22:20 -0400 |
parents | a17bb21b711f |
children | 32b2ed082d0c |
files | bash_command_executer.py |
diffstat | 1 files changed, 44 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bash_command_executer.py Wed Sep 23 15:22:20 2015 -0400 @@ -0,0 +1,44 @@ +#!/usr/bin/env python + + +import sys, subprocess, os + +def stop_err( msg ): + sys.stderr.write( "%s\n" % msg ) + sys.exit() + +def __main__(): + # Get command-line arguments + args = sys.argv + # Remove name of calling program, i.e. ./stderr_wrapper.py + args.pop(0) + + # If there are no arguments left, we're done + if len(args) == 0: + return + + # If one needs to silence stdout + #args.append( ">" ) + #args.append( "/dev/null" ) + + cmdline = " ".join(args) + + + try: + # Run program + err_capture = open("stderr.txt", 'w') + proc = subprocess.Popen( args=cmdline, shell=True, stderr=err_capture, stdout=sys.stdout ) + returncode = proc.wait() + err_capture.close() + + + if returncode != 0: + raise Exception + + except Exception: + # Running Grinder failed: write error message to stderr + err_text = open("stderr.txt").readlines() + stop_err( "ERROR:\n" + "\n".join(err_text)) + + +if __name__ == "__main__": __main__()