Run a shell command (e.g. bcf tools), and return output
(*args)
| 25 | |
| 26 | |
| 27 | def runShellCommand(*args): |
| 28 | """ Run a shell command (e.g. bcf tools), and return output |
| 29 | """ |
| 30 | qargs = [] |
| 31 | for a in args: |
| 32 | if a.strip() != "|": |
| 33 | qargs.append(pipes.quote(a)) |
| 34 | else: |
| 35 | qargs.append("|") |
| 36 | |
| 37 | cmd_line = " ".join(qargs) |
| 38 | logging.info(cmd_line) |
| 39 | |
| 40 | po = subprocess.Popen(cmd_line, |
| 41 | shell=True, |
| 42 | stdout=subprocess.PIPE, |
| 43 | stderr=subprocess.PIPE) |
| 44 | |
| 45 | stdout, stderr = po.communicate() |
| 46 | |
| 47 | po.wait() |
| 48 | |
| 49 | return_code = po.returncode |
| 50 | |
| 51 | if return_code != 0: |
| 52 | raise Exception("Command line {} got return code {}.\nSTDOUT: {}\nSTDERR: {}".format(cmd_line, return_code, stdout, stderr)) |
| 53 | |
| 54 | return stdout |
| 55 | |
| 56 | |
| 57 | def runBcftools(*args): |
no outgoing calls
no test coverage detected