golang 调用cmd执行EXE
package main import ( "bufio" "fmt" "io" "log" "os" "os/exec" // "strings" ) func checkExe2(exeAdress string) { cmd := exec.Command("cmd.exe", "/c", "start "+exeAdress) err := cmd.Run() if err != nil { log.Println("启动失败:", err) } else { log.Println("启动成功!") } } func readCmd(filename string) []string { var cmdStr []string f, err := os.Open(filename) if err != nil { panic(err) } defer f.Close() rd := bufio.NewReader(f) for { line, err := rd.ReadString('\n') //以'\n'为结束符读入一行 cmdStr = append(cmdStr, line) if err != nil || io.EOF == err { break } fmt.Println(line) } return cmdStr } func main() { cmd := readCmd("mqtt_cmd.txt") for _, cmd_str := range cmd { //fmt.Println(cmd_str) checkExe2(cmd_str) } //checkExe2("mqtt_total.exe --pn=STREAMING912 --u=DA61D522DACA29801D89DB4561CAF0F2 --pw=750e672139dc497ee8b26651b2396eae") //checkExe2("mqtt_total.exe --pn=197V5 --u=937F425EC05E1DAA0DB9994EBD0DF129 --pw=eb93514a5470bead3391713259b3f79a") }