Skip to content

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

Closed
@zackw

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    B-unstableBlocker: Implemented in the nightly compiler and unstable.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.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