Skip to content

Commit c09b647

Browse files
authored
Fixed an issue where env variables didn't refresh when launching terminal (#6663)
1 parent 9db1d86 commit c09b647

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Files.Launcher/MessageHandlers/ApplicationLaunchHandler.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Files.Common;
22
using Newtonsoft.Json;
33
using System;
4+
using System.Collections;
45
using System.Collections.Generic;
56
using System.ComponentModel;
67
using System.Diagnostics;
@@ -100,6 +101,14 @@ private async void HandleApplicationLaunch(string application, Dictionary<string
100101
else
101102
{
102103
process.StartInfo.Arguments = arguments;
104+
// Refresh env variables for the child process
105+
foreach (DictionaryEntry ent in Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Machine))
106+
process.StartInfo.EnvironmentVariables[(string)ent.Key] = (string)ent.Value;
107+
foreach (DictionaryEntry ent in Environment.GetEnvironmentVariables(EnvironmentVariableTarget.User))
108+
process.StartInfo.EnvironmentVariables[(string)ent.Key] = (string)ent.Value;
109+
process.StartInfo.EnvironmentVariables["PATH"] = string.Join(";",
110+
Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Machine),
111+
Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.User));
103112
}
104113
process.StartInfo.WorkingDirectory = workingDirectory;
105114
process.Start();

0 commit comments

Comments
 (0)