(use-modules (rnrs io ports)) (use-modules (ice-9 threads)) (define (on-file-change fname thunk) (let* ((input+output (pipe)) (pid (spawn "inotifywait" `("inotifywait" "-m" ,fname) #:output (cdr input+output)))) (close-port (cdr input+output)) (let loop ((line "dummy CLOSE_WRITE")) (unless (eof-object? line) (format #t "read ~s~%" line) (if (string-contains line "CLOSE_WRITE") (thunk)) (loop (get-line (car input+output))))) (close-port (car input+output)) (waitpid pid))) (call-with-new-thread (lambda () (on-file-change "inotify-test.scm" (lambda () (format #t "file changed~%"))))) (format #t "waiting 30s for file change~%") (do ((i 0 (+ i 1))) ((> i 30) (format #t "done loop~%")) (sleep 1) (format #t "tick~%")) (format #t "done waiting~%")