22 lines
729 B
Python
22 lines
729 B
Python
# -*- coding: UTF-8 -*-
|
|
|
|
import sys
|
|
import subprocess
|
|
from log import *
|
|
|
|
# run command and return stdout or None in case of error
|
|
########################
|
|
def run_command(config, task_name, argv, env = None):
|
|
log(LOG_INFO, "Running command '%s' to %s" % (' '.join(argv), task_name))
|
|
try:
|
|
result = subprocess.run(argv, stdout=subprocess.PIPE, env=env)
|
|
if config.verbose:
|
|
log(LOG_INFO, "Command output: %s" % (result.stdout.decode('utf-8')))
|
|
if result.returncode != 0:
|
|
log(LOG_ERROR, "Failed to %s: exit code %d" % (task_name, result.returncode))
|
|
return None
|
|
return result.stdout.decode('utf-8')
|
|
except Exception as e:
|
|
log(LOG_ERROR, "Failed to %s: %s" % (task_name, e))
|
|
return None
|