let ls_output = std::process::Command::new("pwd") .current_dir("./my-project") .output() .expect("Could not ls"); match fs::write("ls.out", ls_output.stdout) { Ok(_) => println!("File saved successfully"), Err(e) => eprintln!("Error saving the file: {}", e), } ``` Writes to file with output: ``` /Users/mfiumara/repos/root-project/my-project