How do you write to a pty master Rust How do you write to a pty master Rust unix unix

How do you write to a pty master Rust


This is expected. std::process::Child::stdin and friends are not set for raw file handles (because Rust doesn't know what they are, the builder doesn't have the master end of your pty).

You can construct your rusty file handle for the master yourself:

fn main() {    let shell = "/bin/bash";    let pty = create_pty(shell);    println!("{:?}", pty);    let mut output = unsafe { File::from_raw_fd(pty.fd) };    write!(output, "touch /tmp/itworks\n");    output.flush();    std::thread::sleep_ms(1000);    println!("{}", pty.process.id());}

You'll see that this does indeed create a file "/tmp/itworks".

(Permalink to the playground)