Crate wtfm_rs_echo_hello_world

Crate wtfm_rs_echo_hello_world 

Source
Expand description

§Get the ouput from echo Hello, world!

use std::process::Command;
let output = Command::new("echo")
    .arg("Hello,")
    .arg("world!")
    .output()
    .expect("Failed to execute command");
let output_1 = String::from_utf8_lossy(&output.stdout).to_string();
assert_eq!(format!("{}", output_1), "Hello, world!\n");
let output_2 = String::from_utf8(output.stdout).expect("Format error");
assert_eq!(format!("{}", output_2), "Hello, world!\n");

std::process::Command

String::from_utf8

String::from_utf8_lossy

After RTFM, we might want to use str::from_utf8:

use std::process::Command;
let output = Command::new("echo")
       .arg("Hello,")
       .arg("world!")
       .output()
       .expect("Failed to execute command");
let hello_world = str::from_utf8(&output.stdout).expect("Format error");
assert_eq!(hello_world, "Hello, world!\n");

Functions§

echo_hello_world
echo_hello_world_v2