It is the same as subprocess.check_output, only it log.debug the command
being run as well as its output.
Signed-off-by: Loic Dachary <loic@dachary.org>
import configobj
import getpass
import socket
+import subprocess
import sys
import tarfile
import time
return True
else:
return searchval == val
+
+
+def sh(command):
+ """
+ Run the shell command and return the output in ascii (stderr and
+ stdout). If the command fails, raise an exception. The command
+ and its output are logged, on success and on error.
+ """
+ log.debug(command)
+ output = ''
+ try:
+ output = subprocess.check_output(command, stderr=subprocess.STDOUT,
+ shell=True)
+ except subprocess.CalledProcessError as e:
+ log.exception(command + " error " + str(e.output))
+ raise e
+ log.debug(command + " output " + str(output))
+ return output.decode('utf-8')