rust cmd stdio demo

Posted 柳清风09

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了rust cmd stdio demo相关的知识,希望对你有一定的参考价值。

use std::process::Command, Stdio;
use std::io::BufRead, BufReader, Write, stdin, Read;
use std::fmt::Error;
use std::thread::spawn;

fn main() 
   run();



fn run() -> Result<(),Error> 
    let result = Command::new("sh")
        //.arg("google.com")
        .stdout(Stdio::piped())
        .stdin(Stdio::piped())
        .spawn()
        .unwrap();

    let stdout = result.stdout.unwrap();
    let reader = BufReader::new(stdout);

    let mut cstdin = result.stdin.unwrap();
    let input  = spawn(move||
        loop
            let mut cmd = String::new();
            stdin().read_line(&mut cmd);
            cstdin.write(&cmd.as_bytes()).expect("err write");
        

    );

    reader.lines()
        .filter_map(|line| line.ok())
        .for_each(|line| println!("", line));

    input.join();
    Ok(())

以上是关于rust cmd stdio demo的主要内容,如果未能解决你的问题,请参考以下文章

rust cmd stdio demo

rust cmd stdio demo

rust cmd stdio demo

Rust安装及创建demo

Rust安装及创建demo

rust-webpack Demo