use anyhow::{Context, Result};
use sh_exec::*;
fn main() -> Result<()> {
use std::time;
env_logger::init();
let path = "/etc";
println!(
"- ls of {path} is {}",
exec!("17068-22053-696", true, "ls {path}")
.with_context(|| format!("Very unexpected - ls failed on {path}"))?
);
println!(
"ls of {path} is {}",
s!("15911-12192-19189", "ls {}", "/")
.with_context(|| "Very unexpected - ls failed on /".to_string())?
);
println!(
"ls of {path} is {}",
exec!("15911-12192-19189", true, "ls {p}", p = "/etc")?
);
let output = exec!("28328-2323-44343", true, "bash -c 'echo Hello World'")?;
println!("Output: {}", output);
s!("14526-30026-17058", "echo Hello World")?;
match s!("28328-2323-3278", "nonexistent_command")
.with_context(|| "Failed to execute command 'nonexistent_command'".to_string())
{
std::result::Result::Ok(output) => println!("Unexpected success: {}", output),
Err(e) => println!("Expected error: {}", e),
}
let ten_secs = time::Duration::from_secs(10);
println!(
"sleep = {:?}",
a!("14526-30888026-777", ten_secs, "sleep 2; echo Hello World")
);
println!("Hello, world!");
let name = read_prompt("What is your name? ");
println!("Hello, {name}!");
println!("Today's date is: {date}", date = e!("date"));
Ok(())
}