Skip to content

Instantly share code, notes, and snippets.

@miguno
Last active March 26, 2022 21:40
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 miguno/1c065016e9df70dcbf9ca80a05759284 to your computer and use it in GitHub Desktop.
Save miguno/1c065016e9df70dcbf9ca80a05759284 to your computer and use it in GitHub Desktop.
Detect whether golang application is reading input from STDIN
func isInputFromStdin() bool {
info, err := os.Stdin.Stat()
if err != nil {
log.Fatal(err)
}
if info.Mode()&os.ModeNamedPipe == 0 {
return false
} else {
return true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment