def write(recv, std): while True: data = recv(256) if not data: if std: with out_lock: stdout.write( "\r\n*** EOF reached; (press F6 or ^Z then enter " "to end)\r\n") stdout.flush() break stream = [stderr_bytes, stdout_bytes][std] with out_lock: stream.write(data) stream.flush()
def windows_shell(chan): # set signal somehow import threading stdout.write("*** Emulating terminal on Windows; press F6 or Ctrl+Z then " "enter to send EOF,\r\nor at the end of the execution.\r\n") stdout.flush() out_lock = threading.RLock() def write(recv, std): while True: data = recv(256) if not data: if std: with out_lock: stdout.write( "\r\n*** EOF reached; (press F6 or ^Z then enter " "to end)\r\n") stdout.flush() break stream = [stderr_bytes, stdout_bytes][std] with out_lock: stream.write(data) stream.flush() threading.Thread(target=write, args=(chan.recv, True)).start() threading.Thread(target=write, args=( chan.recv_stderr, False, )).start() try: while True: d = stdin_bytes.read(1) if not d: chan.shutdown_write() break try: chan.send(d) except socket.error: break except EOFError: # user hit ^Z or F6 pass
def windows_shell(chan): # set signal somehow import threading stdout.write("*** Emulating terminal on Windows; press F6 or Ctrl+Z then " "enter to send EOF,\r\nor at the end of the execution.\r\n") stdout.flush() out_lock = threading.RLock() def write(recv, std): while True: data = recv(256) if not data: if std: with out_lock: stdout.write( "\r\n*** EOF reached; (press F6 or ^Z then enter " "to end)\r\n") stdout.flush() break stream = [stderr_bytes, stdout_bytes][std] with out_lock: stream.write(data) stream.flush() threading.Thread(target=write, args=(chan.recv, True)).start() threading.Thread(target=write, args=(chan.recv_stderr, False,)).start() try: while True: d = stdin_bytes.read(1) if not d: chan.shutdown_write() break try: chan.send(d) except socket.error: break except EOFError: # user hit ^Z or F6 pass