Hacker News new | ask | show | jobs
by burke 4263 days ago
Or, execute "/bin/[ -t 1" (or "test -t 1", or "[[ -t 1 ]]", or ...). This is handy in shellscripts (obviously), but also in languages like Go, which lack a builtin way to test whether stdout is a TTY. e.g.:

    cmd := exec.Command("/bin/[", "-t", "1")
    cmd.Stdout = os.Stdout
    isatty := nil == cmd.Run()
1 comments

Please just call Fstat and check Stat_t.Mode & S_IFCHR
Wow, that's a lot easier than the OS-dependent Syscall6 crap with termios from the "real" solutions I've seen.