use subprocess::Exec;
fn main() -> std::io::Result<()> {
let data = (Exec::cmd("echo").args(&["cherry", "apple", "banana"])
| Exec::cmd("tr").args(&[" ", "\n"])
| Exec::cmd("sort"))
.capture()?
.stdout_str();
println!("Sorted fruits:\n{data}");
let result = (Exec::shell("echo 'hello world'")
| Exec::shell("tr '[:lower:]' '[:upper:]'")
| Exec::shell("rev"))
.capture()?
.stdout_str();
println!("Transformed: {}", result.trim());
let commands = vec![
Exec::shell("echo one two three"),
Exec::shell("tr ' ' '\\n'"),
Exec::cmd("wc").arg("-l"),
];
let line_count = commands
.into_iter()
.collect::<subprocess::Pipeline>()
.capture()?
.stdout_str();
println!("Line count: {}", line_count.trim());
Ok(())
}