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

Comments

Projects
None yet
5 participants
@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

This comment has been minimized.

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

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

@zackw zackw referenced this issue Jan 5, 2017

Merged

Add std::process::Command::envs() #38856

2 of 3 tasks complete

bors added a commit that referenced this issue Jan 25, 2017

Auto merge of #38856 - zackw:process-envs, r=aturon
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

This comment has been minimized.

Copy link
Member

alexcrichton commented May 11, 2017

@rfcbot fcp merge

@rfcbot

This comment has been minimized.

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

This comment has been minimized.

Copy link

rfcbot commented May 23, 2017

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

@zackw

This comment has been minimized.

Copy link
Contributor Author

zackw commented May 23, 2017

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

@Mark-Simulacrum

This comment has been minimized.

Copy link
Member

Mark-Simulacrum commented May 23, 2017

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

@zackw

This comment has been minimized.

Copy link
Contributor Author

zackw commented May 23, 2017

Oh, ok. Thanks for the explanation.

@rfcbot

This comment has been minimized.

Copy link

rfcbot commented Jun 2, 2017

The final comment period is now complete.

sfackler added a commit to sfackler/rust that referenced this issue Jun 16, 2017

sfackler added a commit to sfackler/rust that referenced this issue Jun 19, 2017

sfackler added a commit to sfackler/rust that referenced this issue Jun 20, 2017

@bors bors closed this in 14c2f99 Jun 28, 2017

brson added a commit to brson/rust that referenced this issue Jul 8, 2017

alexcrichton added 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
You can’t perform that action at this time.