This is a creation in Article, where the information may have evolved or changed.
In the execution file//conf//|--app.conf//monitor.exe//app.conf content//command= "ls-l"//Monitordir = "c:\\test"//Under Windows Perform two times//Https://github.com/howeyc/fsnotify/issues/106package Mainimport ("FMT" "Github.com/astaxie/beego" "Gopkg.in/fsnotify.v1" "os/exec" "strings") Func mkcmd (command string) error {A Rgarray: = Strings. Split (Command, "") cmd: = Exec.command (Argarray[0], argarray[1:] ...) Buff, err: = cmd. Output () fmt. Println (String (buff)) if err! = Nil {return ERR} return Nil}func main () {command: = Beego. appconfig.string ("command") Monitordir: = Beego. Appconfig.string ("Monitordir") fmt. Printf ("command=%s, monitordir=%s\n", Command, Monitordir) Watcher, err: = Fsnotify. Newwatcher () if err! = Nil {fmt. PRINTLN (ERR)} Defer watcher. Close () Done: = Make (chan bool)//Process Events go func () {for {select} case EV : = <-watcher. Events://do something if ev. Op&fsnotify. Write = = Fsnotify. Write {err: = mkcmd (command) if err! = Nil {fmt. PRINTLN (ERR)} } Case ERR: = <-watcher. Errors:fmt. PRINTLN (Err)}}} () Err = Watcher. ADD (MONITORDIR) if err! = Nil {fmt. PRINTLN (Err)} <-done watcher. Close ()}