Skip to content

f42h/popen_rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

  • Add the crate to your project
cargo add popen_rs
  • 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.

About

A Tiny Rust Library for Simplified Process Spawning

Topics

Resources

License

Stars

Watchers

Forks

Languages