rust interactive cli code example

Example 1: run commands rust

use std::process::Command;

let mut list_dir = Command::new("ls");

// Execute `ls` in the current directory of the program.
list_dir.status().expect("process failed to execute");

println!();

// Change `ls` to execute in the root directory.
list_dir.current_dir("/");

// And then execute `ls` again but in the root directory.
list_dir.status().expect("process failed to execute");

Example 2: rust compile and run

//In the command line:
---------------------------------------------
>rustc main.rs						//Compiles the main.rs file to main.exe and main.pdb
>main								//Runs the program

Tags:

Rust Example