isatty 判断设备类型
?isatty ?判断设备类型
用??法: int isatty(int handle); ?
一个常见的用法是用来判断当前命令是否使用了没有标准的输出和输入
?
#include <stdio.h> #include <unistd.h>#include <stdlib.h>int main(){ if (!isatty (STDOUT_FILENO)){ printf("is STDOUT_FILENO\n"); }else{ printf("is not STDOUT_FILENO\n"); } if(!isatty (STDIN_FILENO)){ printf("is STDIN_FILENO"); }else{ printf("is not STDIN_FILENO"); }}# ./test is not STDOUT_FILENOis not STDIN_FILENO没有标准的输出和有标准输入# cat aa | ./test is not STDOUT_FILENOis STDIN_FILENO有标准的输出和没有标准输入# ./test >bb# cat bbis STDOUT_FILENOis not STDIN_FILENO
?
?