File: find.rs

package info (click to toggle)
rust-ptyprocess 0.4.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 260 kB
  • sloc: makefile: 4
file content (30 lines) | stat: -rw-r--r-- 819 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/// To run an example run the following command
/// `cargo run --example find`.
///
/// The example is based on https://github.com/zhiburt/ptyprocess/issues/2
use ptyprocess::PtyProcess;
use std::io::{BufRead, BufReader};
use std::process::Command;

fn main() {
    let mut cmd = Command::new("find");
    cmd.args(vec!["/home/", "-name", "foo"]);
    cmd.stderr(std::process::Stdio::null());

    let process = PtyProcess::spawn(cmd).unwrap();
    let mut reader = BufReader::new(process.get_raw_handle().unwrap());

    let mut buf = String::new();
    loop {
        let n = reader.read_line(&mut buf).expect("readline error");
        if n == 0 {
            break;
        }

        // by -1 we drop \n.
        let text = &buf[0..buf.len() - 1];
        println!("buffer: {text}");

        buf.clear();
    }
}