Hacker News new | past | comments | ask | show | jobs | submit login

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()



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.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: