use std::process::Command;
fn main()
{
let some_text = "Testing 123";
let mut output = Command::new("sh");
output.arg("-c").arg("echo Testing 123 | lemonbar -p");
output.status().expect("Error!");
}
I want to pass some_text variable and feed it into lemonbar. Currently this code works just fine. Bu if I write it as output.arg("-c").arg("echo {} | lemonbar -p", some_text); I will have some error. Any idea how to write it in such a way that it works?
output.arg("-c").arg(&format!("echo {} | lemonbar -p", some_text)); Why does the format!() macro need to be used as a reference (as you used & symbol)?
Ah, I guessed that .arg takes a &str as an argument, and since format! returns a String, I had to convert it. However it turns out to be a generic function defined as