int main(void)
{
char s[] = "hello.txt";
int i = 0;
close(STDOUT_FILENO);
//关闭标准输出文件描述符
int fd1 = open("/dev/pts/1", O_WRONLY);
//打开设备文件/dev/pts/1,该设备将做为标准输出文件描述符
int fd = open(s, O_RDONLY);//
if (fd == -1)
{
printf("%s\n", strerror(errno));//
}else
{
while(1)
{
printf("fd1 = %d, fd = %d:%d\n", fd1, fd, i++);
//printf语句将会打印到/dev/pts/1上
sleep(1);//
}
close(fd);
}
return EXIT_SUCCESS;
}
备份地址: 【“隔山打牛”之用open函数改变标准输出】