我通过使用os.ModeCharDevice解决了这个问题:
stat, _ := os.Stdin.Stat()if (stat.Mode() & os.ModeCharDevice) == 0 { fmt.Println("data is being piped to stdin")} else { fmt.Println("stdin is from a terminal")}
我通过使用os.ModeCharDevice解决了这个问题:
stat, _ := os.Stdin.Stat()if (stat.Mode() & os.ModeCharDevice) == 0 { fmt.Println("data is being piped to stdin")} else { fmt.Println("stdin is from a terminal")}