News for hackers. Stuff that matters.
Re:Command Line Interface Guidelines by kergonath on Tuesday February 06, 2024 @11:38AM (#39276497)
> Maybe I’m misunderstanding but sounds like you’re proposing the modifying the command on the left to detect whether it’s piping it’s output (curious how you do that btw sounds pretty cool / useful)

You can do that. Possibly not from all languages but for anything that can call functions in the c standard library, that’s what isatty() is for (among other uses). It takes a file descriptor and returns whether it is a terminal or not. If you do this with stdout, this tells you whether it goes to a terminal or whether it is redirected in a way.

As the parent suspects, though, this won’t tell you anything about what is on the other side of the redirection.

Re:Command Line Interface Guidelines by jasonjmcghee on Tuesday February 06, 2024 @11:45AM (#39276632)
Very cool function - thank you!
Re:Command Line Interface Guidelines by epcoa on Wednesday February 07, 2024 @08:38AM (#39288378)
It also doesn’t tell you what is the terminus of a pipeline. Because often with isatty what you really want to know is if the pipeline ends with a tty. `ls` is screen formatted but `ls | less` is not without extra work.