def remote_exec(command, output_queue: Queue, kill_event: Event,
                done_event: Event, intercept_progress):
    p = subprocess.Popen([
        'ssh', '-o', 'ProxyCommand=ssh -W %h:%p [email protected]',
        '-o', 'StrictHostKeyChecking no', '*****@*****.**',
        command
    ],
                         stderr=subprocess.STDOUT,
                         stdout=subprocess.PIPE,
                         bufsize=0,
                         universal_newlines=True)

    while p.poll() is None:
        if kill_event.is_set():
            p.kill()
            p.wait()
            break

        try:
            line = p.stdout.readline()
            if line is not None and line != '':
                output_queue.put(line)
                if intercept_progress:
                    intercept_log(line, output_queue)
        except:
            p.kill()
            p.wait()

    done_event.returncode = p.returncode
    done_event.set()