or Vec<&str> use proc" /> or Vec<&str> use proc" /> or Vec<&str> use proc"/>

Thin wrapper around [`tokio::process`] to make it streamable

Overview

process-stream

Wraps tokio::process::Command to future::stream.

Install

process-stream = "0.2.2"

Example usage:

From Vec<String> or Vec<&str>

use process_stream::Process;
use process_stream::StreamExt;
use std::io;

#[tokio::main]
async fn main() -> io::Result<()> {
    let ls_home: Process = vec!["/bin/ls", "."].into();

    let mut stream = ls_home.spawn_and_stream()?;

    while let Some(output) = stream.next().await {
        println!("{output}")
    }

    Ok(())
}

From Path/PathBuf/str

use process_stream::Process;
use process_stream::StreamExt;
use std::io;

#[tokio::main]
async fn main() -> io::Result<()> {
    let mut process: Process = "/bin/ls".into();

    // block until process completes
    let outputs = process.spawn_and_stream()?.collect::<Vec<_>>().await;

    println!("{outputs:#?}");

    Ok(())
}

New

use process_stream::Process;
use process_stream::StreamExt;
use std::io;

#[tokio::main]
async fn main() -> io::Result<()> {
    let mut ls_home = Process::new("/bin/ls");
    ls_home.arg("~/");

    let mut stream = ls_home.spawn_and_stream()?;

    while let Some(output) = stream.next().await {
        println!("{output}")
    }

    Ok(())
}

Kill

use process_stream::Process;
use process_stream::StreamExt;
use std::io;

#[tokio::main]
async fn main() -> io::Result<()> {
    let mut long_process = Process::new("/bin/app");

    let mut stream = long_process.spawn_and_stream()?;

    tokio::spawn(async move {
      while let Some(output) = stream.next().await {
        println!("{output}")
      }
    })

    // process some outputs
    tokio::time::sleep(std::time::Duration::new(10, 0)).await;

    // close the process
    long_process.kill().await;

    Ok(())
}
You might also like...
Command-line tool to make Rust source code entities from Postgres tables.

pg2rs Command-line tool to make Rust source code entities from Postgres tables. Generates: enums structs which can be then used like mod structs; use

Make a DAO Drop!

DAO drop tool This tool parses a Cosmos SDK chain export JSON file, to produce a CSV list of addresses and amounts. It can handle extremely large file

rust wrapper for rocksdb

rust-rocksdb Requirements Clang and LLVM Contributing Feedback and pull requests welcome! If a particular feature of RocksDB is important to you, plea

UnQLite wrapper 1.0 is avaliable for Rust

unqlite A high-level UnQLite database engine wrapper. NOTE: Some of the documents is stolen from UnQLite Official Website. What is UnQLite? UnQLite is

An API Wrapper for https://paste.myst.rs written in rust
An API Wrapper for https://paste.myst.rs written in rust

PasteMyst.RS pastemyst-rs is an api wrapper for pastemyst written in Rust. ⚠ This package is under development ⚠ Sample usage To get a paste from past

duckdb-rs is an ergonomic wrapper for using duckdb from Rust.

duckdb-rs duckdb-rs is an ergonomic wrapper for using duckdb from Rust. It attempts to expose an interface similar to rusqlite. Acctually the initial

ODBC wrapper for safe idiomatic Rust

ODBC wrapper for safe idiomatic Rust Library for writing ODBC applications in Rust. If you're looking for raw ODBC FFI bindings check odbc-safe and od

Rusqlite is an ergonomic wrapper for using SQLite from Rust

Rusqlite Rusqlite is an ergonomic wrapper for using SQLite from Rust. It attempts to expose an interface similar to rust-postgres. use rusqlite::{para

Postgres Foreign Data Wrapper for Clerk.com API

Pre-requisites Postgres-15 Rust pgrx Getting Started To run the program locally, clone the repository git clone https://github.com/tembo-io/clerk_fdw.

Comments
  • Question on sending input and listening to a process

    Question on sending input and listening to a process

    What I want:

    1. send some commands to a process;
    2. listen to the feedback from the process(even I don't send command first);

    For the 1st, Seems stdin() is the right method? Is there an example, For the 2ed, the example using next() seems ok. But in my toy process:

    fn main() {
        let mut rng = rand::thread_rng();
        // let v = vec!["ni", "hao", "san", "niu", "fdsfs"];
        let v = vec![1,2,3,4,5,6,7,8,9,10,11,12];
    
        loop {
            let mut input_str = String::new();
            io::stdin()
                .read_line(&mut input_str)
                .expect("get input failed");
            if input_str == "hi\r\n" {
                println!("got it");
            } else {
                let s = v.iter().choose_multiple(&mut rng, 1);
                println!("{}", s[0]);
            }
            sleep(Duration::from_secs(1));
        }
    }
    

    When using next() with it,even I didn't input anything, the process would keep output , which is not what I want. How to fix it?

    opened by dbsxdbsx 9
  • How to solve

    How to solve "stream did not contain valid UTF-8"?

    Sometimes the feedback from the process would give some output not follow UTF-8 codec. Is there a way to work around it? For example, when the output is detected as not UTF-8, then I could decode it with another codec.

    opened by dbsxdbsx 2
Releases(v0.3.0)
  • v0.2.3(Jun 17, 2022)

    Support writing to process

    
    #[tokio::main]
    async fn main() -> io::Result<()> {
        let mut process: Process = Process::new("sort");
    
        // Set stdin (by default is set to null)
        process.stdin(Stdio::piped());
    
        // Get Stream;
        let mut stream = process.spawn_and_stream().unwrap();
    
        // Get writer from stdin;
        let mut writer = process.take_stdin().unwrap();
    
        // Spawn new async task and move stream to it
        let reader_thread = tokio::spawn(async move {
            while let Some(output) = stream.next().await {
                if output.is_exit() {
                    println!("DONE")
                } else {
                    println!("{output}")
                }
            }
        });
    
        // Spawn new async task and move writer to it
        let writer_thread = tokio::spawn(async move {
            writer.write(b"b\nc\na\n").await.unwrap();
            writer.write(b"f\ne\nd\n").await.unwrap();
        });
    
        // Wait till all threads finish
        writer_thread.await.unwrap();
        reader_thread.await.unwrap();
    
    
        Ok(())
    }
    

    Full Changelog: https://github.com/tami5/process-stream/compare/v0.2.2...v0.2.3

    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(May 23, 2022)

Owner
Wandering, exploring, making mistakes and actively pushing limits. (kharji)
null
a tokio-enabled data store for triple data

terminusdb-store, a tokio-enabled data store for triple data Overview This library implements a way to store triple data - data that consists of a sub

TerminusDB 307 Dec 18, 2022
Asyncronous Rust Mysql driver based on Tokio.

mysql-async Tokio based asynchronous MySql client library for rust programming language. Installation Library hosted on crates.io. [dependencies] mysq

Anatoly I 292 Dec 30, 2022
A tokio-uring backed runtime for Rust

tokio-uring A proof-of-concept runtime backed by io-uring while maintaining compatibility with the Tokio ecosystem. This is a proof of concept and not

Tokio 726 Jan 4, 2023
Incomplete Redis client and server implementation using Tokio - for learning purposes only

mini-redis mini-redis is an incomplete, idiomatic implementation of a Redis client and server built with Tokio. The intent of this project is to provi

Tokio 2.3k Jan 4, 2023
📺 Netflix in Rust/ React-TS/ NextJS, Actix-Web, Async Apollo-GraphQl, Cassandra/ ScyllaDB, Async SQLx, Kafka, Redis, Tokio, Actix, Elasticsearch, Influxdb Iox, Tensorflow, AWS

Fullstack Movie Streaming Platform ?? Netflix in RUST/ NextJS, Actix-Web, Async Apollo-GraphQl, Cassandra/ ScyllaDB, Async SQLx, Spark, Kafka, Redis,

null 34 Apr 17, 2023
AsyncRead/AsyncWrite interface for rustls-on-Tokio

rustls-tokio-stream rustls-tokio-stream is a Rust crate that provides an AsyncRead/AsyncWrite interface for rustls. Examples Create a server and clien

Deno 7 May 17, 2023
Awesome books, tutorials, courses, and resources for the Tokio asynchronous runtime ecosystem. ⚡

Awesome Tokio Tokio is an asynchronous runtime for the Rust programming language. It provides the building blocks needed for writing network applicati

Marcus Cvjeticanin 59 Oct 27, 2023
Fault-tolerant Async Actors Built on Tokio

Kameo ???? Fault-tolerant Async Actors Built on Tokio Async: Built on tokio, actors run asyncronously in their own isolated spawned tasks. Supervision

Ari Seyhun 135 Jul 25, 2024
⚡🦀 🧨 make your rust types fit DynamoDB and visa versa

?? ?? dynomite dynomite makes DynamoDB fit your types (and visa versa) Overview Goals ⚡ make writing dynamodb applications in rust a productive experi

Doug Tangren 197 Dec 15, 2022
A Modern Real-Time Data Processing & Analytics DBMS with Cloud-Native Architecture, built to make the Data Cloud easy

A Modern Real-Time Data Processing & Analytics DBMS with Cloud-Native Architecture, built to make the Data Cloud easy

Datafuse Labs 5k Jan 9, 2023