#interactive #process #stdio #unwrap #tiny #result #running


A tiny Rust library for interacting with a running process over stdio

3 releases

0.1.2 Aug 23, 2021
0.1.1 Aug 23, 2021
0.1.0 Aug 22, 2021
Download history 11/week @ 2022-11-29 17/week @ 2022-12-06 12/week @ 2022-12-13 25/week @ 2022-12-20 23/week @ 2022-12-27 44/week @ 2023-01-03 37/week @ 2023-01-10 36/week @ 2023-01-17 30/week @ 2023-01-24 41/week @ 2023-01-31 218/week @ 2023-02-07 250/week @ 2023-02-14 85/week @ 2023-02-21 53/week @ 2023-02-28 40/week @ 2023-03-07 31/week @ 2023-03-14

230 downloads per month
Used in 4 crates (3 directly)


58 lines


crates.io docs.rs

A tiny Rust library for interacting with a running process over stdio.

A common pattern in Unix is to have programs that either produce or consume newline-delimited text over standard input and output (stdio) streams.

This crate provides a light wrapper (really light, look at src/lib.rs) that provides a tidy little abstraction for this pattern on top of Rust's built-in std::process. Besides std, this crate has no dependencies.


The examples in examples/ are instructive. For example, here's echo_stream.rs:

use interactive_process::InteractiveProcess;
use std::{process::Command, thread::sleep, time::Duration};

fn main() {
    /// Use Rust's built-in `std::process` to construct a `Command`.
    /// `examples/echo_stream.py` repeats back lines sent to it,
    /// prefixed with "echo: ".
    let cmd = Command::new("examples/echo_stream.py");

    /// Pass this command to `InteractiveProcess`, along with a
    /// callback. In this case, we'll print every line that the
    /// process prints to `stdout`, prefixed by "Got: ".
    let mut proc = InteractiveProcess::new(cmd, |line| {
        println!("Got: {}", line.unwrap());

    /// Send some data, waiting in between.
    /// The result of this is "Got: echo: data1" being printed by our callback,
    /// since our callback preprends "Got: " and the child process prepends
    /// "echo: ".

    /// Sleep in this thread. Note that the process' `stdout` is processed in
    /// another thread, so while this thread sleeps, that thread will pick
    /// up the message printed by the child process and run the callback.

    /// Repeat that a few more times, for kicks.

    // If we don't sleep here, the process won't have time to reply
    // before we kill it.

    /// We're done with the process, but it is not self-terminating,
    /// so we can't use `proc.wait()`. Instead, we'll take the `Child` from
    /// the `InteractiveProcess` and kill it ourselves.


I've tested this for simple things on Linux, but it's not battle-tested and I haven't tested it on other platforms. If you encounter issues, please open an issue and I'll do my best to work through it with you.

No runtime deps