zoukankan      html  css  js  c++  java
  • Linux重定向的理解

     1 /*
     2     重定向的实例
     3     dup2函数
     4 
     5  利用filefd来代替STDOUT(标准输出流),write写入filefd的数据,重定向写出到STDOUT中;
     6 */
     7 
     8 #include <stdio.h>
     9 #include <sys/stat.h>
    10 #include <string.h>
    11 #include <fcntl.h>
    12 #include <stdlib.h>
    13 #include <unistd.h>
    14 
    15 int main(void)
    16 {
    17    #define STDOUT 1   //标准输出文件描述符号
    18 
    19    int filefd;
    20    char msg[] = "This is a test
    ";
    21 
    22    filefd = open("dup.file", O_CREAT | O_RDWR,
    23       S_IREAD | S_IWRITE);
    24 
    25      
    26     dup2(STDOUT,filefd);
    27 
    28  
    29     write(filefd,msg,strlen(msg));
    30 
    31     close(filefd);
    32      close(STDOUT);
    33     
    34    return 0;
    35 }
    View Code

    基本用处:模块A的输出作为模块B的输入,和函数的功能类似。

    重定向的基本概念:http://blog.csdn.net/lyscsu/article/details/4636287

  • 相关阅读:
    通过存储过程的游标修改某个字段的全部数据
    spring cloud配置注册中心显示服务的ip地址和端口
    git几个必知托管平台
    hdu5790
    hdu5794
    hdu5739
    hdu5829
    线性规划初探
    bzoj4199
    bzoj4197
  • 原文地址:https://www.cnblogs.com/xuxu8511/p/3174114.html
Copyright © 2011-2022 走看看