15. March 2012 08:00
In a C program it can be useful sometimes to know if the stdin / stdout / stderr is actually connected to a termianl or not. There is a function alled isatty() which is dedicated to detecting this. An example is below.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char **argv) {
if (argc < 2) {
printf("ERROR: Need a file descriptor\n");
exit(0);
}
printf("%d\n", isatty(atoi(argv[1])));
return 0;
}
8b679fa9-0948-432f-8ac9-1feb542efbac|0|.0