-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed
Milestone
Description
I'd like to add a method to os/exec.Cmd to ease setting environment variables on commands before they're run.
Manipulating Env []string lists is tedious and error-prone, especially considering potential duplicates. (since programs would others choose either the first or last occurrence, unpredictably)
The proposed Cmd.SetEnv(key, value string) method would be documented as removing duplicates.
On Windows, environment variables are case-insensitive, so the method on Windows should de-dup case insensitively.
This method would replace a handful of copies of func mergeEnvLists that exist in various forms around the standard library, tests, and x/* repos.
dmitshur, jorgebucaran, typeless and flw-cn