4 ms·
Many unix tools already print less logging when used im a script, ie. non-interactively. (I don't know how they detect that.) For example, `ls` has formatting/c
by TobTobXX 7mo ago
Many unix tools already print less logging when used im a script, ie. non-interactively. (I don't know how they detect that.) For example, `ls` has formatting/coloring and `ls | cat` does not. This solution seems like it would fit the problem from the article?
- skydhash 7mo agoThere’s a function isatty that detect if a file descriptor (stdout is one) is associated with a terminal https://man.openbsd.org/man3/ttyname.3 https://man.openbsd.org/man3/ttyname.3 I believe most standard libraries has a version.
- sdsd 7mo agoI was about to comment the same thing. Usually I don't call the function directly, but via the tty command in my shell scripts: if tty -s; then echo "Standard input is a TTY (interactive mode)." else echo "Standard input is not a TTY (e.g., piped or redirected)." fi Now I wonder how _isatty_ itself detects whether a file descriptor is associated with a terminal!
- skydhash 7mo agoIn OpenBSD, with the fcntl system call https://github.com/openbsd/src/blob/master/lib/libc/gen/isatty.c https://github.com/openbsd/src/blob/master/lib/libc/gen/isat... https://man.openbsd.org/fcntl https://man.openbsd.org/fcntl https://github.com/openbsd/src/blob/master/sys/sys/fcntl.h https://github.com/openbsd/src/blob/master/sys/sys/fcntl.h https://github.com/openbsd/src/blob/ba496e5267528b649ec87212f12281fc753215ab/sys/kern/kern_descrip.c#L479 https://github.com/openbsd/src/blob/ba496e5267528b649ec87212... https://github.com/openbsd/src/blob/ba496e5267528b649ec87212f12281fc753215ab/sys/sys/vnode.h#L143 https://github.com/openbsd/src/blob/ba496e5267528b649ec87212...
- zahlman 7mo ago> I don't know how they detect that. The OS knows (it has to because it set up the pipeline), and the process can find out through a system call, exposed in C as `isatty`: https://www.man7.org/linux/man-pages/man3/isatty.3.html https://www.man7.org/linux/man-pages/man3/isatty.3.html > This solution seems like it would fit the problem from the article? Might not be a great idea. The world is probably already full of build tools pipelines that expect to process the normal terminal output (maybe with colours stripped). Environment variables like `CI` are a thing for a reason.