#process #pipe #async #tokio

pwner

Pwner is a Process Owner crate that allows ergonomic access to child processes

8 releases

0.1.8 Nov 15, 2022
0.1.7 Oct 22, 2021
0.1.5 Nov 15, 2020
0.1.3 Apr 7, 2020

#354 in Asynchronous

Download history 9/week @ 2023-11-02 8/week @ 2023-11-09 6/week @ 2023-11-16 16/week @ 2023-11-23 31/week @ 2023-11-30 22/week @ 2023-12-07 13/week @ 2023-12-14 21/week @ 2023-12-21 12/week @ 2023-12-28 6/week @ 2024-01-04 6/week @ 2024-01-11 20/week @ 2024-01-18 12/week @ 2024-01-25 15/week @ 2024-02-01 19/week @ 2024-02-08 104/week @ 2024-02-15

150 downloads per month
Used in rucline

MIT license

52KB
601 lines

pwner

Github MIT licensed Cargo Documentation

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

use std::process::Command;
use pwner::Spawner;

Command::new("ls").spawn_owned().expect("ls command failed to start");

Reading and writing

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

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 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.

Dependencies

~1–11MB
~105K SLoC