Unsatisfied with the solutions presented here so far, I released the python. She was effective. This solution doesn't require setuid permissions or any actually-insane monkey-patching with shared libraries and `LD_LIBRARY_PATH`. #!/usr/bin/env python from sys import argv, stdin, stdout import os if len(argv) < 2: print( """A tragically beautiful piece of hackery, made to fool programs like ls, grep, rg, and fd into thinking they're actually connected to a terminal. Its usage: pty command [arg1 arg2 ...] examples: pty ls --color | less -r ps -eF | pty rg python | less -r""") exit(255) # I've had problems with python's File objects at this low a level, so # we're going to use integers to specify all files in this script. stdin = stdin.buffer.fileno() stdout = stdout.buffer.fileno() # Save the parent stdin and ensure the child inherits it. We're going # to need this later. parent_stdin = os.dup(stdin) os.set_inheritable(parent_stdin, True) pid, ptm = os.forkpty() if pid == 0: # The child runs this. # forkpty maps the pty slave to stdin, stdout, and stderr, but # we want the child to receive from our stdin, in order for things # like `ps -eF | pty rg python` to work. So, overwrite the child's # stdin with that of the parent's. os.dup2(parent_stdin, stdin) os.execvp(argv[1], argv[1:]) # Replace this entire process with argv[1]. else: # The parent runs this. while True: try: chunk = os.read(ptm, 4096) except OSError: break os.write(stdout, chunk) wait_pid, status = os.waitpid(pid, 0) exit(status >> 8)