Continuing from the previous article , I found a way to check the number of unread emails. I need to use go to execute the doveadm command, so I consider using the go exec package.
But after the code is written, it keeps reporting an error: exit status 64, which means the option is wrong, but obviously all options are ok, so it is only possible that I am using the go exec package in the wrong way. Finally, after various attempts, I found that in go exec, All parameters of the command need to be filled in separately.
1 package main 2 3 import ( 4 "bytes" 5 "fmt" 6 "log" 7 "os/exec" 8 "strings" 9 ) 10 11 func main() { 12 cmd := exec.Command("doveadm", "mailbox", "status", "-u", "[email protected]", "-t", "unseen" ,"INBOX") 13 // cmd := exec.Command("doveadm", "mailbox status -u [email protected] -t unseen INBOX") // 这种写法是不对的 14 cmd.Stdin = strings.NewReader("some input") 15 var out bytes.Buffer 16 cmd.Stdout = &out 17 err := cmd.Run() 18 if err != nil { 19 log.Fatal(err) 20 } 21 fmt.Printf("in all caps: %q\n", out.String()) 22 }