Lucas Stadler лет назад: 11
Родитель
Сommit
31735c931c
1 измененных файлов с 16 добавлено и 4 удалено
  1. 16 4
      go/qst.go

+ 16 - 4
go/qst.go

61
61
62
func runAndWatch(file string, cmd string) {
62
func runAndWatch(file string, cmd string) {
63
	// run command, if file changes (mtime) restart command
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
func runShellCmd(cmd string) {
82
func runShellCmd(cmd string) {