31 lines
663 B
Go
31 lines
663 B
Go
//go:build windows
|
|
|
|
package selfupdate
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"syscall"
|
|
)
|
|
|
|
const detachedProcess = 0x00000008
|
|
|
|
// Launch starts exe with args detached from this process, so it outlives the
|
|
// quit that follows.
|
|
func Launch(exe string, args []string) error {
|
|
process, err := startDetached(exe, args)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return process.Release()
|
|
}
|
|
|
|
func startDetached(exe string, args []string) (*os.Process, error) {
|
|
cmd := exec.Command(exe, args...)
|
|
cmd.SysProcAttr = &syscall.SysProcAttr{CreationFlags: detachedProcess | syscall.CREATE_NEW_PROCESS_GROUP}
|
|
if err := cmd.Start(); err != nil {
|
|
return nil, err
|
|
}
|
|
return cmd.Process, nil
|
|
}
|