-
Notifications
You must be signed in to change notification settings - Fork 835
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
Allow environment to be set when invoking Win32 process from WSL #1494
Comments
Obviously related to #1363. |
Don't the Linux env variables get exported as CMD ones? When I started CMD from bash, it still had my TERM variable still set as %TERM%. In Powershell, same thing shows with $env:term. |
Not for me (but very happy to be shown what I'm doing wrong!):
|
Weird. It's working here, 14986. Try starting bash directly instead of from a cmd prompt ( |
Same thing - still %TERM% having been xterm in bash. |
By Jove you're right! |
Is it the same for any variable after you started WSL bash e.g. export FOO=bar
cmd.exe
echo %FOO% Either way - I'm trying to move away from using Cygwin components, so it'd be good to be able to do it using LXSS only! |
@dra27 I agree on that, but the native impementation isn't quite there for me yet (specifically shift+arrowkeys is still locked in the console to text selection, and no OTF support yet). This does seem like a bug though (or maybe the WSLtty behavior is the bug!!). Anyway, I do like the idea! |
@dra27 I hit the same thing, and set up a script to set the analogous VS 2015 environment variables in WSL, and then used |
@therealkenc Thanks, but you seem to be solving a different problem! cl in this case is an irrelevant choice to generate a Win32 executable - the issue is the execve call from LXSS to Win32. My need is to be able to invoke arbitrary Win32 executables from bash but setting arbitrary environment variables for them. I'd be even happier if |
The following seems to work for me:
Then run as, for example, bash's semantics seem to be adequate to handle the few simple cases of quoting that I've thrown at this. I've created a gist with this code if someone wants to improve the string-handling inside the inner loop, if there's some example that doesn't escape properly. |
@aseering Indeed it does, but then my original issue notes that you can achieve it with cmd invocations. If you're going to wrap it in a general purpose script, then for a start the space needs to go from before the double ampersand. I'd question having string escaping as an afterthought - that script doesn't handle cmd escaping at all (trying using a caret symbol, any string with an ampersand) and it's easily open to code injection. Anyway, while I appreciate the script-trickery and realise that others reading the thread may also too, what I'm really after is a Redmond-based "that's a great missing feature, we will [soon/at some point/maybe] add it" or "that's a great feature, but WSL/LXSS is never going to do that". |
@dra27 I'm sure they'll do that. It already does pass envvars in the other direction, right? |
It doesn't, no - I believe only PATH is preserved. What is working usefully is that Win32 processes launched from within LXSS inherit the environment of the Win32 process which started LXSS which means, very usefully, that if you start bash from a VS2015 Tools command prompt then cl, etc. all work - but you can't in bash, for example, say There are some serious complexities to doing this in general (beyond the need to translate directory names from LXSS to Win32), so I wouldn't share your default optimism that this'll make it! |
@dra27 -- I'm sorry that you're having trouble understanding my script; could you perhaps provide an example where it does not work? |
Regarding implementing this -- I personally see WSL's current behavior of stripping environment variables as the feature. I would consider it to be a bug if my entire Linux environment showed up in Windows for a reason analogous to why it would be a bug if WSL used my Windows home directory as its home directory: Linux and Windows use the same names for different things; in general I don't want my Linux state stomping on my Windows state, nor vice versa. There are various clever things that WSL could do. For example, capture environment variables that are set in the new Windows process but not in its parent. I am in general skeptical of this approach; too much magic. I'd rather be explicit. |
@aseering I'm not having any trouble with it - the space before the double-ampersand means that every environment variable ends with a space. Try this (!): WSL is not stripping the environment, they're simply not the same - the technical details already released on Pico processes show that. I agree that automatically exporting all variables would be bad - that's why I'm asking if an explicit syscall might be made available for it. I'd find that considerably more explicit and considerably less inelegant than trying to use a very dodgy shell invocation. |
@dra27 -- apologies -- I read this thread much too quickly and misinterpreted it. I agree with you on all points. |
I'd also like to have some way to explicitly pass environment variables when spawning a Windows process. I'm working on getting the Firefox build working in WSL, which runs cl.exe and other tools. Most things work fine but there are some weird edge cases where I just really need to set |
Any update on this? This breaks many programs like e.g. VSCode since it needs to pass ENV variables to read cli options. |
I'd also like to be able to pass an environment from the node.js exec function. |
In insider build 17063, we introduced a new mechanism to allow op-in environment variable interop. Basically you can set Feedback on this is welcome. |
@jstarks - that's awesome, thanks. I look forward to testing it soon for our build system! |
@jstarks For debugging purposes, what would you recommend? For instance, if I |
There's not a good way to see why the path failed to convert. You have to just reason through it. I'll think about whether this can be improved. In your case, |
Relative paths can't be converted? 🤔 😕 |
Currently no. Should we consider it? It seems a little weird since it would be converted relative to the working directory when you crossed the interop boundary. And we won't necessarily be able to preserve the relativity on the other side of the boundary; we would often have to convert to an absolute path. Other than |
Heh, I think it's just |
As for "scenarios", all of these environment variables are just strings. You can't make any assumptions about their meaning because they mean whatever their inventor meant. My personal take on the |
Note that |
You can alias the hyper command to run through alias hyper="cmd.exe /c hyper" into your |
@samdenty99 - sure, that's fine for the prompt, but it's not great for scripts/build systems. |
When invoking a Win32 process from an LXSS process, it would be useful to have any way of passing some environment variables - for example, via execve(2). The new WSL->Win32 interop is game-changingly great, but having to dance via
cmd /c set FOO=bar && some command
is really awkward (and brittle, given the quoting nightmare).For example, launch bash from a VS2015 Native Tools Command Prompt (ensure FOO unset or run
set FOO=
before invoking bash):linux.c
win.c
Session (
sudo apt-get install gcc
if you don't have gcc!):output is:
desired output would be
FOO=bar
at the end (naturally, if win.c is compiled with gcc and "./win.exe" changed to "./win" then this "works").Build 14986.
The text was updated successfully, but these errors were encountered: