func findProcessID(processName string)(int,error){ buf:=bytes.Buffer{} cmd:=exec.Command("wmic","process","get","name,processid") cmd.Stdout =&buf cmd.Run() cmd2 :=exec.Command("findstr",processName) cmd2.Stdin =&buf data,_:=cmd2.CombinedOutput() if len(data) ==0 { return -1,errors.New("not find") } info:=string(data) reg:=regexp.MustCompile(`[0-9]+`) pid:=reg.FindString(info) return strconv.Atoi(pid) }
go windows进程名获取进程id
猜你喜欢
转载自blog.csdn.net/qq_33048069/article/details/103798356
今日推荐
周排行