Closed
Description
You can add a vector of command-line arguments to a Command object with .args()
, but there's no equivalent for environment variables. I'd like to be able to do things like
let filtered_env : Vec<(String, String)> =
std::env::vars().filter(|&(ref k, ref v)| /* criterion */).collect();
let status = Command::new("printenv")
.stdin(Stdio::null())
.stdout(Stdio::inherit())
.env_clear()
.envs(filtered_env)
.status();
Right now I have to do instead
let mut cmd = Command::new("printenv");
cmd.stdin(Stdio::null());
cmd.stdout(Stdio::inherit());
cmd.env_clear();
for (ref k, ref v) in filtered_env {
cmd.env(k, v);
}
let status = cmd.status();
which breaks the builder pattern and extends the scope of the Command object.