package cmd import ( "fmt" "regexp" ) func SCQueryStatus(serviceName string) (state string, err error) { args := []string{"/c", "sc", "query", serviceName} ret, err := Command("cmd.exe", args) //fmt.Printf("ret : %v\n", ret) compile := regexp.MustCompile(`(\d{1,4}):`) states := compile.FindStringSubmatch(ret) if len(states) < 2 { compile = regexp.MustCompile(` r'STATE\s+:\s+(\d+)'`) states = compile.FindStringSubmatch(ret) fmt.Printf("%v\n", states) if len(states) > 1 { state = states[1] } } else { state = states[1] } return }