Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
zackw opened this issue Dec 22, 2016 · 8 comments
Closed

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

zackw opened this issue Dec 22, 2016 · 8 comments
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@zackw
Copy link
Contributor

zackw commented Dec 22, 2016

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.

@brson brson added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Dec 22, 2016
@brson
Copy link
Contributor

brson commented Dec 22, 2016

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

zackw added a commit to zackw/rust that referenced this issue Jan 5, 2017
Command::envs() adds a vector of key-value pairs to the child
process environment all at once.  Suggested in rust-lang#38526.
bors added a commit that referenced this issue Jan 25, 2017
Add std::process::Command::envs()

`Command::envs()` adds a vector of key-value pairs to the child
process environment all at once.  Suggested in #38526.

This is not fully baked and frankly I'm not sure it even _works_, but I need some help finishing it up, and this is the simplest way to show you what I've got.  The problems I know exist and don't know how to solve, from most to least important, are:

* [ ] I don't know if the type signature of the new function is correct.
* [x] The new test might not be getting run.  I didn't see it go by in the output of `x.py test src/libstd --stage 1`.
* [x] The tidy check says ``process.rs:402: different `since` than before`` which I don't know what it means.

r? @brson
@alexcrichton alexcrichton added B-unstable Blocker: Implemented in the nightly compiler and unstable. and removed C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Feb 8, 2017
@alexcrichton
Copy link
Member

@rfcbot fcp merge

@rfcbot
Copy link

rfcbot commented May 11, 2017

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.

@rfcbot
Copy link

rfcbot commented May 23, 2017

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

@rfcbot rfcbot added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label May 23, 2017
@zackw
Copy link
Contributor Author

zackw commented May 23, 2017

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

@Mark-Simulacrum
Copy link
Member

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

@zackw
Copy link
Contributor Author

zackw commented May 23, 2017

Oh, ok. Thanks for the explanation.

@rfcbot
Copy link

rfcbot commented Jun 2, 2017

The final comment period is now complete.

@bors bors closed this as completed in 14c2f99 Jun 28, 2017
brson pushed a commit to brson/rust that referenced this issue Jul 8, 2017
alexcrichton pushed a commit to brson/rust that referenced this issue Jul 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants