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.
The following snippet builds a crystal program that prints
ENV["FOO"]?and then calls that program withclear_env: trueand theFOOvariable assigned: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: trueusescmd /c setto validate the effect, so we didn't notice this before.Add a 👍 reaction to issues you find important.