diff --git a/src/util/command.py b/src/util/command.py new file mode 100644 index 0000000..2aa260b --- /dev/null +++ b/src/util/command.py @@ -0,0 +1,27 @@ +import subprocess + + +def execute(command) -> None: + """Execute bash `command`, return the returncode (int)""" + command = command.split(' ') + subprocess.call(command) + + +def get_output(command) -> str: + """Get standard output of `command`""" + command = command.split(' ') + return subprocess.run( + command, + stderr=subprocess.STDOUT, + stdout=subprocess.PIPE + ).stdout.decode('utf-8') + + +def get_return_code(command) -> int: + """get return code of `command` (int)""" + command = command.split(' ') + return subprocess.run( + command, + stderr=subprocess.STDOUT, + stdout=subprocess.PIPE + ).returncode