Skip to content

Command/environment variable interaction is confusing and error-prone #28975

Closed
@Diggsey

Description

@Diggsey

The API which Command exposes implies that environment variables are captured from the parent process at the point where it is constructed, and then may be subsequently modified through the use of env/env_remove/env_clear.

However, in reality the environment variables are captured lazily, when the first environment modifier is applied to the command. There's also no way to explicitly trigger the environment capture without actually modifying the environment.

This results in unpredictable behaviour if environment variables are modified between Command construction, and Command execution. Perhaps this is done as an optimization. However, spawning a new process far outweighs the cost of copying a few strings.

Environment variables are global state: it's a bad idea for accesses to global state to happen at an unpredictable time.

Finally, regardless of whether the behaviour is changed, it should be clearly documented what the behaviour is.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-acceptedCategory: A feature request that has been accepted pending implementation.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions