diff options
author | BonfaceKilz | 2021-02-16 16:08:23 +0300 |
---|---|---|
committer | BonfaceKilz | 2021-02-16 16:22:11 +0300 |
commit | 227577e0532787fe58da85b0aab02e686ecc6662 (patch) | |
tree | 4ed0ca11e9360c1b84d56c67c785f637e7a3c67d | |
parent | 996cb799aa5c12e67b8af91a08b424a3a3c21359 (diff) | |
download | genenetwork3-227577e0532787fe58da85b0aab02e686ecc6662.tar.gz |
gn3: commands: Add new procedure for running a command
* gn3/commands.py (run_command): New procedure.
-rw-r--r-- | gn3/commands.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/gn3/commands.py b/gn3/commands.py index 9692f62..e5a3b1e 100644 --- a/gn3/commands.py +++ b/gn3/commands.py @@ -1,5 +1,7 @@ """Procedures used to work with the various bio-informatics cli commands""" +import subprocess + from datetime import datetime from typing import Dict from typing import List @@ -69,3 +71,14 @@ supported: conn.rpush("GN2::job-queue", unique_id) return unique_id + + +def run_cmd(cmd: str) -> Dict: + """Run CMD and return the CMD's status code and output as a dict""" + results = subprocess.run(cmd, capture_output=True, + shell=True, check=False) + out = str(results.stdout, 'utf-8') + if results.returncode > 0: # Error! + out = str(results.stderr, 'utf-8') + return {"code": results.returncode, + "output": out} |