From ae4c86b1e4fcce9651feeed5c4f2a0cf41acd986 Mon Sep 17 00:00:00 2001 From: LiFeng <1160040543@qq.com> Date: Wed, 15 Apr 2026 14:31:46 +0800 Subject: [PATCH] fix(shell/windows): Before setting the PATH environment variable, create a new shell. --- internal/shell/win.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/internal/shell/win.go b/internal/shell/win.go index 83d3776..7bbc5aa 100644 --- a/internal/shell/win.go +++ b/internal/shell/win.go @@ -211,6 +211,12 @@ func (s *Shell) SetPath(path string) { } path = TidyWindowsPathEnv(path) + s := NewShell() + if s.KeyInfo == nil { + gprint.PrintError("Windows registry key is closed.") + return + } + oldPathValue, _, err := s.Key.GetStringValue(PathEnvName) if err != nil { gprint.PrintError("Get env $path failed: %+v", err) @@ -235,6 +241,12 @@ func (s *Shell) UnsetPath(path string) { } path = TidyWindowsPathEnv(path) + s := NewShell() + if s.KeyInfo == nil { + gprint.PrintError("Windows registry key is closed.") + return + } + oldPathValue, _, err := s.Key.GetStringValue(PathEnvName) if err != nil { gprint.PrintError("Get env $path failed: %+v", err)