You could use isatty It requires a file-descriptor, and to make sure you are not relying on implementation of stdin, you should use fileno(stdin) to get the file-descriptor for stdin. Obviously, if stdin is the tty (keyboard input, essentially), then it isatty() will return non-zero. If it's a file, pipe or some such, then it will return zero.