Files
newt/updates/reexec_windows.go
Owen c058500932 Auto update newt
Former-commit-id: 42cb8e7908
2026-05-28 15:38:08 -07:00

29 lines
623 B
Go

//go:build windows
package updates
import (
"fmt"
"os"
"os/exec"
)
// reexec on Windows cannot use syscall.Exec (there is no exec syscall that
// replaces the process image). Instead we start a new process and exit the
// current one.
func reexec(exePath string) error {
cmd := exec.Command(exePath, os.Args[1:]...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Env = os.Environ()
if err := cmd.Start(); err != nil {
return fmt.Errorf("failed to start updated binary: %w", err)
}
// Exit the current process so the new binary takes over.
os.Exit(0)
return nil // unreachable
}