Skip to content

Instantly share code, notes, and snippets.

@veggiemonk
Created August 23, 2025 18:42
Show Gist options
  • Save veggiemonk/b39fae610d5d2e7e30ad33b2dd300276 to your computer and use it in GitHub Desktop.
Save veggiemonk/b39fae610d5d2e7e30ad33b2dd300276 to your computer and use it in GitHub Desktop.
test if data is coming in STDIN in Go
package main
import (
"fmt"
"os"
"golang.org/x/term"
)
// https://go.dev/play/p/iuo-AZ1oRPk
func main() {
fmt.Println("IsTerminal", term.IsTerminal(int(os.Stdin.Fd())))
if isInputFromPipe() {
fmt.Println("stdin has data")
} else {
fmt.Println("stdin doesn't have data")
}
fmt.Println("os.Args", os.Args)
}
func isInputFromPipe() bool {
fi, _ := os.Stdin.Stat()
return (fi.Mode() & os.ModeCharDevice) == 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment