https://github.com/m-lima/pwner
Pwner is a Process Owner crate that allows ergonomic access to child processes
https://github.com/m-lima/pwner
pipes process rust
Last synced: 8 months ago
JSON representation
Pwner is a Process Owner crate that allows ergonomic access to child processes
- Host: GitHub
- URL: https://github.com/m-lima/pwner
- Owner: m-lima
- License: mit
- Created: 2020-04-06T18:14:50.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-11-15T22:23:43.000Z (almost 3 years ago)
- Last Synced: 2025-01-22T17:49:50.335Z (9 months ago)
- Topics: pipes, process, rust
- Language: Rust
- Homepage: https://docs.rs/pwner
- Size: 95.7 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pwner
[](https://github.com/m-lima/pwner/actions?workflow=build)
[](LICENSE)
[](https://crates.io/crates/pwner)
[](https://docs.rs/pwner)Pwner is a Process Owner crate that allows ergonomic access to child processes.
This module creates the possibility of owning a child and having convenient methods to read and write, while also killing the process gracefully upon dropping.
## Spawning an owned process
```rust
use std::process::Command;
use pwner::Spawner;Command::new("ls").spawn_owned().expect("ls command failed to start");
```## Reading and writing
```rust
use std::io::{BufRead, BufReader, Write};
use std::process::Command;
use pwner::Spawner;let mut child = Command::new("cat").spawn_owned()?;
child.write_all(b"hello\n")?;let mut output = String::new();
let mut reader = BufReader::new(child);
reader.read_line(&mut output)?;assert_eq!("hello\n", output);
```## Stopping an owned process
The owned process is terminated whenever it is dropped.
### Example
```rust
use std::process::Command;
use pwner::Spawner;{
let child = Command::new("ls").spawn_owned().expect("ls command failed to start");
}
// child is killed when dropped out of scope
```## Graceful dropping
**Note:** Only available on *nix platforms.
When the owned process gets dropped, [`Process`][__link0] will try to kill it gracefully by sending a `SIGINT`. If the process still doesn’t die, a `SIGTERM` is sent and another chance is given, until finally a `SIGKILL` is sent.
[__link0]: https://docs.rs/pwner/0.1.8/pwner/trait.Process.html