Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> detects stdout redirects

Is there a portable way for you to find out that stdout is connected to output.txt? isatty() only tells you that there may be a redirection and I suppose on linux you could use /proc/self/fd/1 but I don't know how to do it portably.



If output is redirected, ag calls fstat on stdout and records the inode. It then ignores files based on inode rather than path:

https://github.com/ggreer/the_silver_searcher/blob/b995d3b82...




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

Search: