Skip to content

ENV propagation broken when spawining process with clear_env: true on MSYS2 #17046

Description

@straight-shoota

The following snippet builds a crystal program that prints ENV["FOO"]? and then calls that program with clear_env: true and the FOO variable assigned:

File.write("env-var.cr", %(puts ENV["FOO"]?))

Process.run("crystal", ["build", "env-var.cr"])

Process.run(File.join(".", "env-var"), clear_env: true, env: {"FOO" => "BAR"}, output: :inherit)

This should print BAR. It does so on all platforms, except MSYS2 (both CLANGARM64 and UCRT64) where the output is empty.

It works as expected with clear_env: false.
When reading the environment variable with a system command works as well (both "cmd", ["/c", "echo %FOO%"] and "sh", ["-c", "echo $FOO"]).

It seems to be that just the Crystal program is unable to read the environment properly.

Running the Crystal program through "cmd", ["/c", ".\\env-var"] doesn't help either. In fact, it doesn't even pick up env vars set after in cmd with "cmd", ["/c", "set FOO=BAZ && .\\env-var"]. 😕

The spec for clear_env: true uses cmd /c set to validate the effect, so we didn't notice this before.


Add a 👍 reaction to issues you find important.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind:bugA bug in the code. Does not apply to documentation, specs, etc.platform:windows-gnuWindows support based on the MinGW-w64 toolchain + MSYS2topic:stdlib:system

    Type

    Fields

    No fields configured for Bug.

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions