def execute(command, return_output=True, log_file=None, log_settings=None, error_logfile=None, timeout=None, line_function=None, poll_timing = 0.01, logger=None, working_folder=None, env=None):
    tmp_log = False
    if log_settings:
        log_folder = log_settings.get('LOG_FOLDER')
    else:
        tmp_log = True
        log_folder = tempfile.mkdtemp()
    if not log_file:
        log_file = os.path.join(log_folder, "commands", "execute-command-logfile-%s.log" % UUID.uuid4())
        try:
            if not os.path.isdir(os.path.join(log_folder, "commands")):
                os.makedirs(os.path.join(log_folder, "commands"))
        except:
            pass
    if not logger:
        logger = logging.getLogger('command_execute')
    logfile_writer = open(log_file, 'a')
    header = "%s - Executing command (timeout=%s) :\n\t%s\n\n\n" % (datetime.now().isoformat(), timeout, command)
    logfile_writer.write(header)
    logfile_writer.flush()
    logfile_reader = open(log_file, 'rb')
    logfile_reader.seek(0, os.SEEK_END)
    logfile_start_position = logfile_reader.tell()
    if error_logfile:
        err_logfile_writer = open(error_logfile, 'a')
    else:
        err_logfile_writer = logfile_writer
    start = datetime.now()
    timeout_string = ""
    if timeout:
        timeout_string = "(timeout=%s)" % timeout
    logger.info(u"Executing command %s :\n\t\t%s" % (timeout_string, command) )
    if sys.platform != 'win32':
        command = u"exec %s" % text_utils.uni(command)
    process = subprocess.Popen(command, stdout=logfile_writer, stderr=err_logfile_writer, bufsize=1, shell=True, cwd=working_folder, env=env)
    while process.poll() == None:
        time.sleep(poll_timing)
        if timeout != None:
            now = datetime.now()
            if (now - start).seconds> timeout:
                os.kill(process.pid, signal.SIGKILL)
                os.waitpid(-1, os.WNOHANG)
                raise Exception("Command execution timed out (took more than %s seconds...)" % timeout)
        if line_function:
            o = text_utils.uni(logfile_reader.readline()).rstrip()
            while o != '':
                line_function(o)
                o = text_utils.uni(logfile_reader.readline()).rstrip()
    if not return_output:
        return process.wait()
    logfile_reader.seek(logfile_start_position, os.SEEK_SET)
    res = text_utils.uni(logfile_reader.read())
    try:
        logfile_reader.close()
        logfile_writer.close()
        err_logfile_writer.close()
        if tmp_log:
            shutil.rmtree(log_folder, ignore_errors=True)
    except:
        logger.exception("Error while cleaning after tbx.execute() call.")
    return res