//go:build windows package daemon import ( "os/exec" "syscall" ) // detachedProcess is the Win32 flag DETACHED_PROCESS: no console window, no // binding to the caller's console. const detachedProcess = 0x00000008 // createBreakawayFromJob is the Win32 flag CREATE_BREAKAWAY_FROM_JOB: the // child leaves the parent's job object, so a session-bound job (WinRM, SSH, // CI) does not take the daemon down with it. Only works when the job allows // it; Spawn falls back to a start without the flag otherwise. const createBreakawayFromJob = 0x01000000 // detach detaches the child from the console: own process group (no Ctrl-C // from the shell) and no console (no flashing window). func detach(cmd *exec.Cmd, breakaway bool) { flags := uint32(syscall.CREATE_NEW_PROCESS_GROUP | detachedProcess) if breakaway { flags |= createBreakawayFromJob } cmd.SysProcAttr = &syscall.SysProcAttr{CreationFlags: flags} }