-
Notifications
You must be signed in to change notification settings - Fork 822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Environment variables set in bash aren't picked up by Windows processes run from bash #1363
Comments
For anyone hitting this, you can sort-of work around it with some wrapper batch files. I have one setup.bat:
And then, e.g. to run msbuild via msbuild.bat:
Then set up an alias:
I'm able to run start, nuget, and msbuild this way, which is so far what I really wanted. |
For the same reasons I described here arguing against automatic translation of commandline arguments, I'd argue against automatic translation of environment variables--it's going to be hard to get right in the general sense. I would like to have some way to set environment variables when spawning a Windows process, but making it explicitly opt-in sounds more sensible. |
We added an opt-in mechanism for environment variable interop in insider build 17063. You set WSLENV to a list of environment variables that should be passed through. |
Another surprise of todays announcements 🎉 |
Please use the following bug reporting template to help produce actionable and reproducible issues. Please try to ensure that the reproduction is minimal so that the team can go through more bugs!
Some Windows processes depend on the environment for their behavior. One is msbuild when trying to compile a Visual Studio solution; Microsoft.Common.CurrentVersion.targets tries to set some properties using $([System.IO.Path]::GetTempPath()), which resolves to the value of %TMP%, %TEMP%, %USERPROFILE%, or the Windows directory, whichever is found first. TMP, TEMP, and USERPROFILE are not set in bash by default, and unfortunately setting them doesn't work.
Consider the following MSBuild script:
Output from msbuild 14.0 in cmd.exe looks like this:
Even though TMP, TEMP, and USERPROFILE are all set, the output is wrong:
If it matters, the above is run under tmux.
Edit: I'm seeing similar weirdness when running windows commands from bash to do windows things. For example, if I run "start ./Solution.sln" from cmd.exe it will open Solution.sln using the associated Visual Studio and everything is fine. If I set an alias for 'start' to 'cmd.exe /c start' in bash, and run the same command, Visual Studio opens but throws a bunch of errors and eventually crashes with a 'debug' or 'close program' dialog. It's not clear whether this is environment related or not, but it seems likely to me.
14965.rs_prerelease.161104-1700
Install WSL, install VS2015, set up alias, etc. as shown.
The strace is pretty straightforward. I can attach the entire thing if required, but in particular the environment variables show up w/ execve if I run 'strace -v -s 65535 ', e.g.:
See our contributing instructions for assistance.
The text was updated successfully, but these errors were encountered: