Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
burke
on Oct 21, 2014
|
parent
|
context
|
favorite
| on:
Hints for writing Unix tools
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()
ksherlock
on Oct 21, 2014
[–]
Please just call Fstat and check Stat_t.Mode & S_IFCHR
burke
on Oct 21, 2014
|
parent
[–]
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: