Add command execution using subprocess

This commit is contained in:
ItsDrike 2020-10-22 18:02:52 +02:00
parent 9d1012656d
commit 7872a839d8
No known key found for this signature in database
GPG key ID: F4E8FF4F6AC7F3B4

27
src/util/command.py Normal file
View file

@ -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