Skip to content

Latest commit

History

26 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

send_ctrlc

CrateDocsBuildcodecov

A cross platform crate for interrupting or terminating child processes

Install

cargo add send_ctrlc
# Or for async/tokio:
cargo add send_ctrlc -F tokio

Features

  • Cross platform (including Windows)
  • Uniform cross platform API
  • Both sync and async
  • Only 2 unsafe calls
  • Minimal dependencies:
    • Synchronous: libc on unix, and windows-sys on windows
    • Asynchronous: tokio (with only process feature)

Examples

The first example below is for synchronous use cases and the second for tokio/async use cases. However, both interrupt and terminate are available for both sync/async code.

use send_ctrlc::{Interruptibleas _,InterruptibleCommandas _};// Interrupt example#[cfg(not(feature = "tokio"))]fnmain(){// Create a continuous ping standard commandletmut command = std::process::Command::new("ping");#[cfg(windows)]
command.arg("-t");
command.arg("127.0.0.1");// Spawn the ping, interrupt it, and wait for it to completeletmut child = command.spawn_interruptible().unwrap();
child.interrupt().unwrap();
child.wait().unwrap();}// Terminate example (async/tokio)#[cfg(feature = "tokio")]#[tokio::main]asyncfnmain(){// Create a continuous ping standard commandletmut command = tokio::process::Command::new("ping");#[cfg(windows)]
command.arg("-t");
command.arg("127.0.0.1");// Spawn the ping, interrupt it, and wait for it to completeletmut child = command.spawn_interruptible().unwrap();
child.terminate().unwrap();
child.wait().await.unwrap();}

Contributions

Contributions are welcome as long they align with the vision for this crate.

About

Cross platform crate for sending interrupts/ctrl-c to child processes

Resources

Stars

9 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages