Skip to main content

ON_A_TERMINAL

Constant ON_A_TERMINAL 

Source
const ON_A_TERMINAL: &str = r#"import os, pty, sys
pid, fd = pty.fork()
if pid == 0:
    os.execv(sys.argv[1], [sys.argv[1]])
out = b""
while True:
    try:
        b = os.read(fd, 4096)
    except OSError:
        break
    if not b:
        break
    out += b
sys.stdout.write(out.decode(errors="replace"))
_, status = os.waitpid(pid, 0)
sys.exit(os.waitstatus_to_exitcode(status))
"#;
Expand description

Run argv[1] as the leader of a new session on a new pty, print what it writes, and exit with its status.