Parcourir la Source

rerun if mtime changes.

Lucas Stadler 11 ans auparavant
Parent
commit
31735c931c
1 fichiers modifiés avec 16 ajouts et 4 suppressions
  1. 16 4
      go/qst.go

+ 16 - 4
go/qst.go

@ -61,10 +61,22 @@ func main() {
61 61
62 62
func runAndWatch(file string, cmd string) {
63 63
	// run command, if file changes (mtime) restart command
64
	// for now: run command until it exits, wait a bit, run again
65
	runShellCmd(cmd)
66
	time.Sleep(1 * time.Second)
67
	runAndWatch(file, cmd)
64
	lastMtime := time.Unix(0, 0)
65
	for {
66
		info, err := os.Stat(file)
67
		if err != nil {
68
			log.Fatalf("Error: %s disappeared, exiting.", file)
69
		}
70
71
		mtime := info.ModTime()
72
		if mtime.After(lastMtime) {
73
			log.Printf("%s changed, rerunning", file)
74
			runShellCmd(cmd)
75
		}
76
77
		lastMtime = mtime
78
		time.Sleep(1 * time.Second)
79
	}
68 80
}
69 81
70 82
func runShellCmd(cmd string) {