Quantcast
Channel: C++博客-所有随笔
Viewing all articles
Browse latest Browse all 7881

文件描述符重定向测试

$
0
0
 
这是《Unix环境高级编程》第三章的一道习题,考察文件描述符的重定向问题。为此我写了个测试程序查看上述两条命令的区别。
#include <stdio.h>
#include 
<stdlib.h>
#include 
<fcntl.h>
#include 
<unistd.h>

int main()
{
   write(STDOUT_FILENO,
"hello,stdout",sizeof("hello,stdout");
   write(STDERR_FILENO,
"hello,stderr",sizeof("hello,stderr");
   
return 0;
}
编译为a.out,运行以上两条命令发现:
第一条命令结果是都输出到文件outfile中;第二条命令结果是出错信息输出到控制台,正常信息输出到文件outfile中。


大大木马 2013-05-21 17:36 发表评论

Viewing all articles
Browse latest Browse all 7881

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>