From 316ebbb502819af43f7bbd66d062573d92ecf37b Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Sun, 9 Aug 2020 19:20:33 +0200 Subject: [PATCH] Inject Env Variables in WSL shell command --- src/extension/shell.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/extension/shell.rs b/src/extension/shell.rs index 2a77aff..0c6a30b 100644 --- a/src/extension/shell.rs +++ b/src/extension/shell.rs @@ -43,6 +43,8 @@ pub enum Shell { impl Shell { fn execute_cmd(&self, cmd: &str, vars: &HashMap) -> std::io::Result { + let mut is_wsl = false; + let mut command = match self { Shell::Cmd => { let mut command = Command::new("cmd"); @@ -55,11 +57,13 @@ impl Shell { command } Shell::WSL => { + is_wsl = true; let mut command = Command::new("bash"); command.args(&["-c", &cmd]); command } Shell::WSL2 => { + is_wsl = true; let mut command = Command::new("wsl"); command.args(&["bash", "-c", &cmd]); command @@ -84,6 +88,22 @@ impl Shell { command.env(key, value); } + // In WSL environment, we have to specify which ENV variables + // should be passed to linux. + // For more information: https://devblogs.microsoft.com/commandline/share-environment-vars-between-wsl-and-windows/ + if is_wsl { + let mut tokens: Vec<&str> = Vec::new(); + tokens.push("CONFIG/p"); + + // Add all the previous variables + for (key, _) in vars.iter() { + tokens.push(key); + } + + let wsl_env = tokens.join(":"); + command.env("WSLENV", wsl_env); + } + command.output() }