Skip to content
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 to be passed into WSL #14

Closed
goreliu opened this issue Oct 23, 2016 · 10 comments
Closed

environment variables to be passed into WSL #14

goreliu opened this issue Oct 23, 2016 · 10 comments

Comments

@goreliu
Copy link

goreliu commented Oct 23, 2016

  • A brief description

/init cmd /C set contains too few environment variables, some softwares run failed, like shutdown. In bash.exe, everything is OK.

$ /init shutdown
The system could not find the environment option that was entered.(203)

$ /init cmd /C 'set COMPUTERNAME=MY-PC & shutdown'
Usage: shutdown ...

And without TMP variable, some softwares run failed.

$ /init cmd /C set
COMSPEC=C:\WINDOWS\System32\cmd.exe
PATH=C:\WINDOWS\SYSTEM32;C:\WINDOWS;C:\WINDOWS\SYSTEM32\WBEM;C:\WINDOWS\SYSTEM32\WINDOWSPOWERSHELL\V1.0;C:\WINDOWS\SYSTEM32;C:\WINDOWS;%LOCALAPPDATA%\MICROSOFT\WINDOWSAPPS;C:\WINDOWS\SYSTEM32\WBEM;C:\WINDOWS\SYSTEM32\WINDOWSPOWERSHELL\V1.0;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\mine\app\0misc\bin;C:\Users\goreliu\AppData\Local\Microsoft\WindowsApps
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.JS;.WS;.MSC
PROMPT=$P$G
SYSTEMDRIVE=C:
SYSTEMROOT=C:\WINDOWS
WINDIR=C:\WINDOWS
  • Your Windows build number
14951.1000
  • Steps / All commands required to reproduce the error from a brand new installation
/init shutdown

microsoft/WSL#1257

@mintty
Copy link
Owner

mintty commented Oct 23, 2016

See my comment in the WSL issue. I suggest you reopen it.

@mintty mintty closed this as completed Oct 23, 2016
@mintty mintty reopened this Oct 23, 2016
@mintty
Copy link
Owner

mintty commented Oct 23, 2016

So you are effectively asking to transfer all environment variables to WSL.
Have you tested whether that's not already the case, perhaps? What if you call wsl.bat after setting a variable?

@mintty mintty changed the title "/init cmd /C set" contains too few environment variables, some softwares run failed environment variables to be passed into WSL Oct 23, 2016
@goreliu
Copy link
Author

goreliu commented Oct 23, 2016

I will test it later.

@mintty
Copy link
Owner

mintty commented Oct 23, 2016

@rprichard wslbridge does not seem to take over the environment to WSL. Could that be added?

@rprichard
Copy link

wslbridge has an -E option that transfers explicitly listed variables. (The syntax is either -E VAR to transfer VAR or -E VAR=VAL to set VAR to VAL.) It doesn't currently have a way to copy all the environment variables.

FWIW: When I last checked, Microsoft's bash.exe adapter didn't copy anything. If wslbridge did copy all the variables, I'd have a few questions about the behavior:

(1) Does wslbridge unset variables that weren't set on the Cygwin side?
(2) Maybe wslbridge would only set variables that weren't already set on the WSL side?
(3) Are certain variables blacklisted? (e.g. PATH, HOME, TMPDIR, others?)

@goreliu
Copy link
Author

goreliu commented Oct 23, 2016

@rprichard There are two kinds of variables: WSL variables (wslbridge-backend need them, -E VAR) and Windows variables (bash.exe need them).

@goreliu
Copy link
Author

goreliu commented Oct 24, 2016

@mintty

c:\Users\goreliu\AppData\Local\wsltty>bash
[goreliu@my-pc wsltty]$ /init cmd /C set | wc -l
39
[goreliu@my-pc wsltty]$
c:\Users\goreliu\AppData\Local\wsltty>wsl
c:\Users\goreliu\AppData\Local\wsltty>

In mintty ...

[goreliu@my-pc wsltty]$ /init cmd /C set | wc -l
7
[goreliu@my-pc wsltty]$
c:\Users\goreliu\AppData\Local\wsltty>set foo=abc
c:\Users\goreliu\AppData\Local\wsltty>echo %foo%
abc
c:\Users\goreliu\AppData\Local\wsltty>bash
[goreliu@my-pc wsltty]$ /init cmd /C "echo %foo%"
abc
[goreliu@my-pc wsltty]$ exit
c:\Users\goreliu\AppData\Local\wsltty>wsl
c:\Users\goreliu\AppData\Local\wsltty>

In mintty ...

[goreliu@my-pc wsltty]$ /init cmd /C "echo %foo%"
%foo%
[goreliu@my-pc wsltty]$

@rprichard
Copy link

Oh, I see. wslbridge probably just needs to call to cygwin_internal(CW_SYNC_WINENV), like winpty does.

@mintty
Copy link
Owner

mintty commented Oct 24, 2016

Ah, yes, that sounds like a good idea.

@mintty
Copy link
Owner

mintty commented Nov 18, 2016

Updated to wslbridge 0.2.1 with wsltty 0.7.0.

@mintty mintty closed this as completed Nov 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants