3 ms·
> 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 red
by wyldfire 10y ago
> 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.
- charliesome 10y agoIf 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/b995d3b8269b9c395c1dc9ee45f0df9203942df9/src/options.c#L342-L347 https://github.com/ggreer/the_silver_searcher/blob/b995d3b82...