Files
forego/windows.go
T
Peter Waller 9c2bf670ca Refactor interrupt monitoring and shutdown
This makes it so that the same goroutine responsible for starting
processes shuts them down. This is a stepping stone to a larger refactor
whose goal is to eliminate race conditions.
2014-05-21 08:37:21 +01:00

35 lines
653 B
Go

package main
// +build windows
import (
"fmt"
"os"
"os/exec"
"syscall"
)
func (p *Process) Start() {
command := []string{"cmd", "/C", p.Command}
p.cmd = exec.Command(command[0], command[1:]...)
p.cmd.Dir = p.Root
p.cmd.Env = p.envAsArray()
p.cmd.Stdin = p.Stdin
p.cmd.Stdout = p.Stdout
p.cmd.Stderr = p.Stderr
p.cmd.Start()
}
func (p *Process) Signal(signal syscall.Signal) {
group, _ := os.FindProcess(-1 * p.cmd.Process.Pid)
group.Signal(signal)
}
func ShutdownProcesses(of *OutletFactory) {
for name, ps := range processes {
of.SystemOutput(fmt.Sprintf("terminating %s", name))
ps.cmd.Process.Signal(os.Kill)
}
os.Exit(1)
}