{"body":"from subprocess import Popen\nimport termios,\tsys, tty, pty, os, select\n\ncommand = 'gcc -Wl,-t -o /tmp/dummy_name -lexpat'.split(\" \")\n# command = 'docker run -it --rm centos /bin/bash'.split()                                                                                      \n\n# save original tty setting then set it to raw mode                                                                                             \nold_tty = termios.tcgetattr(sys.stdin)\ntty.setraw(sys.stdin.fileno())\n\n# open pseudo-terminal to interact with subprocess                                                                                              \nmaster_fd, slave_fd = pty.openpty()\n\n\ntry:\n    # use os.setsid() make it run in a new process group, or bash job control will not be enabled                                               \n    p = Popen(command,\n              preexec_fn=os.setsid,\n              stdin=slave_fd,\n              stdout=slave_fd,\n              stderr=slave_fd,\n              universal_newlines=True)\n\n    while p.poll() is None:\n\tr, w, e = select.select([sys.stdin, master_fd], [], [])\n\tif sys.stdin in r:\n            d = os.read(sys.stdin.fileno(), 10240)\n            os.write(master_fd, d)\n\telif master_fd in r:\n            o = os.read(master_fd, 10240)\n            if o:\n                os.write(sys.stdout.fileno(), o)\nfinally:\n    # restore tty settings back                                                                                                                 \n    termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_tty)\n\n\n\n","name":"","extension":"txt","url":"https://www.irccloud.com/pastebin/h5D3795u","modified":1653373388,"id":"h5D3795u","size":1559,"lines":38,"own_paste":false,"theme":"","date":1653373388}