From 227577e0532787fe58da85b0aab02e686ecc6662 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Tue, 16 Feb 2021 16:08:23 +0300 Subject: gn3: commands: Add new procedure for running a command * gn3/commands.py (run_command): New procedure. --- gn3/commands.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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} -- cgit v1.2.3