tokio-process-tools
A library designed to assist with interacting and managing processes spawned via the tokio runtime.
Features
- Inspecting stdout/stderr streams synchronously and asynchronously.
- Collecting stdout/stderr streams synchronously and asynchronously into some new structure.
- Waiting for specific output on stdout/stderr.
- Gracefully terminating a process or killing it if unresponsive.
Example Usage
Here is an example that demonstrates how to spawn a process, handle its output, and gracefully terminate it using this library.
use crateBroadcastOutputStream;
use crateNext;
use crateProcessHandle;
async
Installation
Add the following line to your Cargo.toml to include this library as part of your project:
[]
= "0.5.7"
Ensure that the tokio runtime is also set up in your project. Only use the features you need!:
[]
= { = "1.45.0", = ["full"] }
IMPORTANT:
This libraries TerminateOnDrop type requires your code to run in a multithreaded runtime! Dropping a
TerminateOnDrop in a single-threaded runtime will lead to a panic.
This also holds for unit tests! Annotate your tokio-enabled tests dealing with a TerminateOnDrop with
async
to not run into problems.
Contributing
We welcome contributions! Please fork the repository, create a feature branch, and send a pull request. Make sure your
code follows Rust’s idiomatic practices (cargo fmt and cargo clippy checks) and includes relevant tests.