#=====================================================================================================
# execute a shell command, and return the output
#===================================================================================================== 
import subprocess                                              #import module

def exec(command):    
    output = ''
    if type(command) is str:
        exec = subprocess.call(command, shell=True)
    else:
        exec = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        (stdout,stderr) = exec.communicate()
        if stdout:
            stdout  = stdout.decode("utf-8")
            output += stdout
        if stderr:
            stderr  = stderr.decode("utf-8")
            output += stderr
    return(output)
#=====================================================================================================