Connect `stdin` directly to stream input

Hi, i’m trying to connect what comes from stdin directly into a UnixStream and what comes out of it directly to stdout.

Here’s what i’m doing currently:

let stdout = io::stdout();
let mut stdout_handle = stdout.lock();

let stdin = io::stdin();

loop {
    let mut input = String::new();
    stdin.read_line(&mut input).unwrap();


    match buffer[..]) {
        Ok(n) => {
        Err(e) => {println!("Something occured: {}", e);}


It works but stdin.read_line(&mut input).unwrap(); blocks and i’ve to wait a bit to get the response from the UnixStream. How could I achieve this in an asynchronous fashion?

Would something like stdin.bytes().peekable() help?

Take a look at the tokio process crate - it’ll allow you to work with the stdin/stdout streams asynchronously.

You can also create background threads that service stdin/stderror I/O (in a blocking manner) and let the main thread orchestrate between them.