0
点赞
收藏
分享

微信扫一扫

系统编程 文件描述符重定向

open打开一个文件,返回的是该文件文件描述符

程序中 用文件描述符表管理 文件描述符  默认1024个 【0-1023】

0  1   2  被系统占用  0是标准输入,1是标准输出,2是标准错误


#include <stdio.h>
#include <unistd.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>


int main()
{
    //open打开一个文件,返回的是该文件文件描述符
    //程序中 用文件描述符表管理 文件描述符  默认1024个 【0-1023】 0  1   2  被系统占用  0是标准输入,1是标准输出,2

    int fd = open("./change_get.txt",O_RDWR|O_CREAT,0777);
    dup2(fd,1);
    printf("这是重定向后输出\n");
    return 0;
}

举报

相关推荐

0 条评论