The following redirect_stdout program demonstrates how to redirect a child process's stdout to a file in Rust, like the shell command ls -l > dir.txt. It opens the file and passes it to Command::stdout().
This zip file contains the complete crate.