Skip to content

feature request: std::process::Command.envs() #38526

Description

@zackw

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.

Activity

  1. added
    T-libs-api[DEPRECATED; DO NOT USE]
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    on Dec 22, 2016
  2. brson commented on Dec 22, 2016

    @brson
    Contributor

    This sounds reasonable to me considering args. If you want to submit a PR for the feature go ahead.

  3. added a commit that references this issue on Jan 5, 2017
  4. added a commit that references this issue on Jan 25, 2017
  5. added
    B-unstableBlocker: Implemented in the nightly compiler and unstable.
    and removed
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    on Feb 8, 2017
  6. alexcrichton commented on May 11, 2017

    @alexcrichton
    Member

    @rfcbot fcp merge

  7. rfcbot commented on May 11, 2017

    @rfcbot

    Team member @alexcrichton has proposed to merge this. The next step is review by the rest of the tagged teams:

    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 this document for info about what commands tagged team members can give me.

  8. rfcbot commented on May 23, 2017

    @rfcbot

    🔔 This is now entering its final comment period, as per the review above. 🔔

  9. added
    final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.
    on May 23, 2017
  10. zackw commented on May 23, 2017

    @zackw
    ContributorAuthor

    I'm confused; hasn't this already been merged?

  11. Mark-Simulacrum commented on May 23, 2017

    @Mark-Simulacrum
    Member

    Yes, but it's currently unstable. The FCP above starting means that the libs team believes the API is ready for stabilization.

  12. zackw commented on May 23, 2017

    @zackw
    ContributorAuthor

    Oh, ok. Thanks for the explanation.

  13. rfcbot commented on Jun 2, 2017

    @rfcbot

    The final comment period is now complete.

  14. added a commit that references this issue on Jul 8, 2017
    ef7ecda
  15. added a commit that references this issue on Jul 13, 2017
    15a95aa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    B-unstableBlocker: Implemented in the nightly compiler and unstable.T-libs-api[DEPRECATED; DO NOT USE]final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions