2018-03-13 00:33:39 +01:00
|
|
|
import logging
|
2019-08-25 00:40:39 +02:00
|
|
|
import subprocess
|
2018-03-13 00:33:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
def run_program(cmd, show=True):
|
2019-09-06 22:49:49 +02:00
|
|
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
|
2018-03-13 00:33:39 +01:00
|
|
|
stdout, stderr = p.communicate()
|
2019-08-25 00:27:31 +02:00
|
|
|
stderr = stderr.decode("utf-8", "replace")
|
2018-03-13 00:33:39 +01:00
|
|
|
if p.returncode != 0 and show:
|
|
|
|
msg = stderr.strip()
|
2021-12-18 21:36:16 +01:00
|
|
|
logging.error("Something went wrong: %s", msg)
|
2018-03-13 00:33:39 +01:00
|
|
|
return p.returncode, stdout, stderr
|