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`. Save this script somewhere in your `PATH`. Don't forget to `chmod +x` it. Suppose you save this script as `pty`. #!/usr/bin/env python from sys import argv import os # 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 = 0 stdout = 1 stderr = 2 if len(argv) < 2: os.write(stderr, b"""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 -R | less -r git log -p | pty rg <search terms> | less -r """) exit(255) # We do not use forkpty here because it would block ^Cs from reaching the # child process. And we don't need that. ptm, pts = os.openpty() pid = os.fork() if pid == 0: # The child runs this. # To get the behaviour we want, we only need to replace the process's # stdout with pts. Everything else should remain in place, so that things # like `ps -eF | pty rg python | less -r` will still work as intended. os.dup2(pts, stdout) # This is not like a subprocess.call(). It replaces the entire child # process with argv[1:], meaning execvp will not return! Web search # "fork exec" for more. os.execvp(argv[1], argv[1:]) # The parent runs this. # If the parent doesn't close the slave end, the script won't be able to # exit. The next read on ptm after the child process terminates would hang # forever because pts would technically still be open. os.close(pts) while True: try: chunk = os.read(ptm, 4096) except OSError: wait_pid, status = os.waitpid(pid, 0) exit(status >> 8) os.write(stdout, chunk)