popen_rs

Crates.iopopen_rs
lib.rspopen_rs
version0.1.0
created_at2025-07-24 09:50:17.713134+00
updated_at2025-07-24 09:50:17.713134+00
descriptionSimple Process Spawning Library
homepage
repositoryhttps://github.com/f42h/popen_rs
max_upload_size
id1765863
size7,859
(f42h)

documentation

README

popen_rs - Simple Process Spawning Library

Description

This small Rust library simplifies the process of running system commands by 
spawning a new child process and reading the content of either the stdout 
or stderr stream handle.

Usage

  • Import the popen_rs crate to your source file
use popen_rs::Popen;

Methods

spawn

Spawns a new child process and captures the handles of stdout and stderr. This function will return the content of either stdout or stderr.
pub fn spawn(&mut self) -> io::Result<String>

pid

Requests the OS specified process identifier of the current child process.
pub fn pid(&mut self) -> Option<u32>

Example

use popen_rs::Popen;

fn main() {
    let command = "ls -l";
    let mut process = Popen::new(command);

    match process.spawn() {
        Ok(output) => {
            let pid = process.pid().unwrap();

            println!("Output of `{}` [PID:{}]:", command, pid);
            println!("\n{}", output);
        },
        Err(err) => eprintln!("Error: {}", err),
    }
}

License

This project is published under the MIT License.

Commit count: 0

cargo fmt