Is stdin and console and keyboard input same
Is stdin and console and key开发者_Go百科board input same in C?
From the isatty(3)
man page:
The isatty() function tests whether fd is an open file descriptor referring to a terminal.
#include <unistd.h>
int isatty(int fd);
isatty() returns 1 if fd is an open file descriptor referring to a terminal; otherwise 0 is returned, and errno is set to indicate the error.
So, isatty(stdin)
will return nonzero if it is being typed, and zero if it's being redirected.
Yes, that's correct. You can essentially have a read() system call to accept input from stdin.
Not necessarily. stdin
can be redirected from a file (e.g. executable < input
) or some other non-interactive device.
amphetamachine's answer gives you the tool to tell the difference.
精彩评论