An example isatty:
#include <unistd.h>
#include <stdio.h>
int main()
{
if( isatty(STDIN_FILENO) )
puts("Connected to a terminal");
else
puts("Not connected to a terminal");
return 0;
}
Using:
$ gcc isatty.c
$ ./a.out
Connected to a terminal
$ echo hello | ./a.out
Not connected to a terminal
Not much easier!
source
share