Last active
March 26, 2022 21:40
-
-
Save miguno/1c065016e9df70dcbf9ca80a05759284 to your computer and use it in GitHub Desktop.
Detect whether golang application is reading input from STDIN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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