def shell_command(command):

    command = pipes.quote(" ".join(command))
    command = ['sh', '-c', "'%s'"%(command)]
    try:
        p = subprocess.Popen(command
                             , stdout=subprocess.PIPE
                             , stderr=subprocess.PIPE)

        out, err = p.communicate()
    except Exception as e:
        return '', 'error'
    else:
        return out, err

    # Redirecting the stdout to use the output elsewhere
command is a list of ['cmd','arg1','arg2',...]
dataset/ETHPy150Open aerospike/aerospike-admin/lib/util.py/shell_command