I need a command line utility to behave different if some string is piped into its STDIN. Here\'s some minimal example:
package main // file test.go
import
If none of the above works for you, try this way:
stat, err := os.Stdin.Stat()
if err != nil {
return nil, fmt.Errorf("you have an error in stdin:%s", err)
}
if (stat.Mode() & os.ModeNamedPipe) == 0 {
return nil, errors.New("you should pass smth to stdin")
}
It worked for me in both darwin (Mac OS) and linux (Ubuntu).