github.com/mutagen-io/mutagen@v0.18.0-rc1/cmd/mutagen/project/common_windows.go (about) 1 package project 2 3 import ( 4 "errors" 5 "os" 6 "os/exec" 7 "path/filepath" 8 ) 9 10 // runInShell runs the specified command using the system shell. On Windows 11 // systems, this is %ComSpec% (with a fallback to a fully qualified cmd.exe if 12 // %ComSpec% is not an absolute path (which includes cases where it's empty)). 13 func runInShell(command string) error { 14 // Determine the shell to use. 15 shell := os.Getenv("ComSpec") 16 if !filepath.IsAbs(shell) { 17 systemRoot := os.Getenv("SystemRoot") 18 if !filepath.IsAbs(systemRoot) { 19 return errors.New("invalid ComSpec and SystemRoot environment variables") 20 } 21 shell = filepath.Join(systemRoot, "System32", "cmd.exe") 22 } 23 24 // Set up the process. 25 process := exec.Command(shell, "/c", command) 26 process.Stdin = os.Stdin 27 process.Stdout = os.Stdout 28 process.Stderr = os.Stderr 29 30 // Run the process and wait for its completion. 31 return process.Run() 32 }