Skip to content

Instantly share code, notes, and snippets.

@larzconwell
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larzconwell/11299422 to your computer and use it in GitHub Desktop.
Save larzconwell/11299422 to your computer and use it in GitHub Desktop.
// Writes stdin to output.log
package main
import (
"os"
"io"
)
func main() {
output, err := os.Create("output.log")
if err != nil {
panic(err)
}
defer output.Close()
_, err = io.Copy(output, os.Stdin)
if err != nil {
panic(err)
}
}
// Prints when output.log is modified
package main
import (
"fmt"
"github.com/howeyc/fsnotify"
)
func main() {
watcher, err := fsnotify.NewWatcher()
if err != nil {
panic(err)
}
defer watcher.Close()
go func() {
for {
select {
case err := <-watcher.Error:
if err != nil {
panic(err)
}
case ev := <-watcher.Event:
fmt.Println(ev)
}
}
}()
err = watcher.Watch("output.log")
if err != nil {
panic(err)
}
select {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment