在(v1) Alpine终端上,我希望设置一个环境变量,该变量被传递到一个Windows可执行文件中。有办法这样做吗?
我希望打印“你好,世界!”的例子:
windows-10:~# export X=World
windows-10:~# cmd.exe /c 'echo Hello, %X%!'
Hello, %X%!见下面飞利浦的回答。
以下是来自https://learn.microsoft.com/en-us/windows/wsl/interop的相关信息的副本
在Windows和WSL之间共享环境变量
Available in Windows Insider builds 17063 and later.在17063之前,只有WSL可以访问的Windows环境变量是PATH (因此您可以从WSL下启动Win32可执行文件)。
从17063开始,WSL和Windows共享WSLENV,这是为连接运行在WSL上的Windows和Linux发行版而创建的一个特殊环境变量。
WSLENV的特性:
It is shared; it exists in both Windows and WSL environments.
It is a list of environment variables to share between Windows and WSL.
It can format environment variables to work well in Windows and WSL.WSLENV中有四个标志可以影响环境变量的转换方式。
WSLENV标志:
/p - translates the path between WSL/Linux style paths and Win32 paths.
/l - indicates the environment variable is a list of paths.
/u - indicates that this environment variable should only be included when running WSL from Win32.
/w - indicates that this environment variable should only be included when running Win32 from WSL.可以根据需要组合标志。
发布于 2020-02-26 22:08:51
你能试试这个吗?
~$ export X=World
~$ export WSLENV=X/w
~$ cmd.exe /c 'echo Hello, %X%!'
Hello, World!https://stackoverflow.com/questions/60422936
复制相似问题