Change:
You can add a vector of command-line arguments to a Command object with , but there's no equivalent for environment variables. I'd like to be able to do things like let filteredenv : Vec<(String, String)= std::env::vars().filter( / criterion /).collect(); let status = Command::new("printenv") .stdin(Stdio::null()) .stdout(Stdio::inherit()) .envclear() .envs(filteredenv) .status(); Right now I have to do instead let mut cmd = Command::new("printenv"); (Stdio::null()); (Stdio::inherit()); cmd.envclear(); for (ref k, ref v) in filtered_env { (k, v); } let status = (); which breaks the builder pattern and extends the scope of the Command object.
This sounds reasonable to me considering . If you want to submit a PR for the feature go ahead.
fcp merge
Team member has proposed to merge this. The next step is review by the rest of the tagged teams: [x] [x] [x] [x] [x] [x] [x] No concerns currently listed. Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See for info about what commands tagged team members can give me.
:bell: This is now entering its final comment period, as per the . :bell:
I'm confused; hasn't this already been merged?
Yes, but it's currently . The FCP above starting means that the libs team believes the API is ready for stabilization.
Oh, ok. Thanks for the explanation.
The final comment period is now complete.

Discussion:
///         .expect("ls command failed to start"); /// ``` #[stable(feature = "process", since = "1.0.0")] <del> pub fn args<S: AsRef<OsStr>>(&mut self, args: &[S]) -> &mut Command { </del> <ins> pub fn args<I, S>(&mut self, args: I) -> &mut Command where I: IntoIterator<Item=S>, S: AsRef<OsStr> { </ins> for arg in args { self.arg(arg.as_ref()); }

self } <ins> /// Add or update multiple environment variable mappings. /// /// # Examples /// /// Basic usage: /// ```no_run /// use std::process::{Command, Stdio}; /// use std::env; /// use std::collections::HashMap; /// /// let filtered_env : HashMap<String, String> = ///     env::vars().filter(|&(ref k, _)| ///         k == "TERM" || k == "TZ" || k == "LANG" || k == "PATH" ///     ).collect(); /// /// Command::new("printenv") ///         .stdin(Stdio::null()) ///         .stdout(Stdio::inherit()) ///         .env_clear() ///         .envs(&filtered_env) ///         .spawn() ///         .expect("printenv failed to start"); /// ``` #[unstable(feature = "command_envs", issue = "38526")] pub fn envs<I, K, V>(&mut self, vars: I) -> &mut Command where I: IntoIterator<Item=(K, V)>, K: AsRef<OsStr>, V: AsRef<OsStr> { for (ref key, ref val) in vars { self.inner.env(key.as_ref(), val.as_ref()); } self } </ins> /// Removes an environment variable mapping. /// /// # Examples

<ins> // Copyright 2014, 2017 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms. // ignore-emscripten #![feature(command_envs)] use std::process::Command; use std::env; use std::collections::HashMap; #[cfg(all(unix, not(target_os="android")))] pub fn env_cmd() -> Command { Command::new("env") } #[cfg(target_os="android")] pub fn env_cmd() -> Command { let mut cmd = Command::new("/system/bin/sh"); cmd.arg("-c").arg("set"); cmd } #[cfg(windows)] pub fn env_cmd() -> Command { let mut cmd = Command::new("cmd"); cmd.arg("/c").arg("set"); cmd } fn main() { // save original environment let old_env = env::var_os("RUN_TEST_NEW_ENV"); env::set_var("RUN_TEST_NEW_ENV", "123"); // create filtered environment vector let filtered_env : HashMap<String, String> = env::vars().filter(|&(ref k, _)| k == "PATH").collect(); let mut cmd = env_cmd(); cmd.env_clear(); cmd.envs(&filtered_env); // restore original environment match old_env { None => env::remove_var("RUN_TEST_NEW_ENV"), Some(val) => env::set_var("RUN_TEST_NEW_ENV", &val) } let result = cmd.output().unwrap(); let output = String::from_utf8_lossy(&result.stdout); assert!(!output.contains("RUN_TEST_NEW_ENV"), "found RUN_TEST_NEW_ENV inside of:nn{}", output); } </ins>

Some(val) => env::set_var("RUN_TEST_NEW_ENV", &val) } <del> let prog = cmd.spawn().unwrap(); let result = prog.wait_with_output().unwrap(); </del> <ins> let result = cmd.output().unwrap(); </ins> let output = String::from_utf8_lossy(&result.stdout); assert!(!output.contains("RUN_TEST_NEW_ENV"),