Timeline for How does a program know if stdout is connected to a terminal or a pipe?
Current License: CC BY-SA 4.0
11 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Sep 29, 2023 at 19:51 | comment | added | Cory Kendall | This is a pretty brilliant answer. | |
| Jul 20, 2022 at 9:05 | comment | added | conny | Thanks for highlighting -t, I've read the help a million times but never registered that it exists ⭐️ | |
| Nov 6, 2021 at 16:45 | comment | added | Ian D. Allen | This Perl bit works to tell if stdin is seekable: $ date | perl -e 'binmode STDIN ; seek(STDIN,0,0) or exit 1' || echo Perl bad seek gives output Perl bad seek because of the pipe, but is silent if you redirect stdin from a file. | |
| Aug 13, 2019 at 16:48 | vote | accept | mowwwalker | ||
| Aug 13, 2019 at 3:56 | comment | added | dessert | @mowwwalker If this answer solved your issue, please take a moment and accept it by clicking on the check mark to the left. That will mark the question as answered and is the way thanks are expressed on the Stack Exchange sites. | |
| May 8, 2019 at 5:32 | comment | added | user313992 | On BSD, lseek will succeed on terminals and other character devices, and simply re/set a counter which is increased on each successful read(). I don't know whether this makes them "seekable". | |
| Apr 27, 2019 at 15:49 | comment | added | Sergiy Kolodyazhnyy | Another, Linux-specific approach is to traverse /proc directory and for each /proc/<integer>/ directory look into /proc/<integer>/fd/ and find file descriptor that has same inode number in pipefs serverfault.com/q/48330/363611 However, that is only useful in scripts when one cannot use the syscalls described in Stephane's answer, and is more of a workaround than proper solution IMHO | |
| Apr 27, 2019 at 6:34 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 | added 64 characters in body |
| Apr 27, 2019 at 6:20 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 | added 2294 characters in body |
| Apr 27, 2019 at 0:16 | history | edited | Jeff Schaller♦ | CC BY-SA 4.0 | deleted 5 characters in body |
| Apr 26, 2019 at 20:50 | history | answered | Stéphane Chazelas | CC BY-SA 4.0 |