Skip to content

Instantly share code, notes, and snippets.

Created March 4, 2020 21:02
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Know if a go program is receiving stdin input or not
package main
import (
func main() {
fi, err := os.Stdin.Stat()
if err != nil {
logrus.Error("error reading from stdin")
logrus.Infof("File Mode %s", fi.Mode())
logrus.Infof("Os Mode Named Pipe %s", os.ModeNamedPipe)
logrus.Infof("Operation %s", fi.Mode()&os.ModeNamedPipe)
if fi.Mode()&os.ModeNamedPipe == 0 {
logrus.Infof("No STDIN Input")
} else {
var data []byte
data, err = ioutil.ReadAll(os.Stdin)
if err != nil {
logrus.Errorf("error reading from file %v", err)
logrus.Infof("There is STDIN '%s'", data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment