Home

Get The Text Output From An External Command In Rust

use std::process::Command;

fn main() {
    let args = vec!["-l"];
    let response = Command::new("ls")
        .args(args)
        .output()
        .expect("did not work");
    let text = String::from_utf8_lossy(&response.stdout);
    dbg!(text);
}

- The default that comes back from output is a [TODO: Code shorthand span ] that has to be turned into a string to output it if you want to see it as letters.

- I wouldn't be surprised to find other ways to do this.

~ fin ~