mirror of
https://github.com/fosrl/newt.git
synced 2026-07-16 03:46:25 -05:00
29 lines
623 B
Go
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
|
|
}
|