fix: 隐藏 Windows 上 git 子进程的控制台窗口
This commit is contained in:
@@ -38,6 +38,7 @@ func (g *GitClient) Run(path string, args ...string) (string, error) {
|
||||
argsArr := append(header, args...)
|
||||
log.Println(argsArr)
|
||||
cmd := exec.CommandContext(ctx, "git", argsArr...)
|
||||
hideWindow(cmd)
|
||||
var stdout, stderr bytes.Buffer
|
||||
cmd.Stdout = &stdout
|
||||
cmd.Stderr = &stderr
|
||||
|
||||
8
internal/git/hidewindow_other.go
Normal file
8
internal/git/hidewindow_other.go
Normal file
@@ -0,0 +1,8 @@
|
||||
//go:build !windows
|
||||
|
||||
package git
|
||||
|
||||
import "os/exec"
|
||||
|
||||
// hideWindow 非 Windows 平台无需处理
|
||||
func hideWindow(cmd *exec.Cmd) {}
|
||||
14
internal/git/hidewindow_windows.go
Normal file
14
internal/git/hidewindow_windows.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// hideWindow 在 Windows 上隐藏子进程的控制台窗口
|
||||
func hideWindow(cmd *exec.Cmd) {
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||
HideWindow: true,
|
||||
CreationFlags: 0x08000000, // CREATE_NO_WINDOW
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user