'Execute a gdb command and capture its output
Args:
- gdb_command (String)
- silent: discard command\'s output, redirect to /dev/null (Bool)
Returns:
- output of command (String)'

def execute_redirect(self, gdb_command, silent=False):

    result = None
    if silent:
        logfd = open(os.path.devnull, 'r+')
    else:
        logfd = tmpfile()
    logname = logfd.name
    gdb.execute('set    logging    off')
    gdb.execute('set    height    0')
    gdb.execute(('set    logging    file    %s' % logname))
    gdb.execute('set    logging    overwrite    on')
    gdb.execute('set    logging    redirect    on')
    gdb.execute('set    logging    on')
    try:
        gdb.execute(gdb_command)
        gdb.flush()
        gdb.execute('set    logging    off')
        if (not silent):
            logfd.flush()
            result = logfd.read()
        logfd.close()
    except Exception as e:
        gdb.execute('set    logging    off')
        if (config.Option.get('debug') == 'on'):
            msg(('Exception    (%s):    %s' % (gdb_command, e)), 'red')
            traceback.print_exc()
        logfd.close()
    if (config.Option.get('verbose') == 'on'):
        msg(result)
    return result
