Reputation: 920
Basically I'm trying to check if anything is in stdin when the program is called, so if I've got another file called output that writes to stdout then
./output | ./program
should work and ./program
should exit with an error
Upvotes: 4
Views: 560
Reputation: 1353
isatty
checks for a tty, not a pipe. Use fstat(STDIN_FILENO, &sb)
instead and check for S_ISFIFO(sb.st_mode)
.
To check whether there is anything "in" stdin that you could possibly read, you use, for example poll(2)
with an event mask of POLLIN
.
Upvotes: 3