特别声明:
建议使用google游览器,火狐也可以
论坛处于测试阶段,一切资料都为测试资料,在论坛正式运行的时候,会尽量保存网友的劳动成果!
HelloWorld论坛秉持互惠互利,共同学习与进步,一个人的梦想大家实现的理想,一直坚持着,望广大网友多多支持,提供宝贵意见
来论坛做什么?
可以先转载你平时学习查找的资料(先论坛查找),自己可以写写体会
把平时碰到的问题,如何解决可以先记录在论坛,以备后来的人学习
可以和会员一起参加一些开源项目的学习,汉化,推广,甚至可以加入团队
|
|
来源:http://yonghan.blog.sohu.com/94105721.html dup和dup2函数的作用
#include <unistd.h>
// 这些函数返回的新文件描述符与参数filedes2共享同一个文件表项。 //dup和dup2都是系统服务,window平台对应DuplicateHandle函数 /* DUP.C: This program uses the variable old to save * the original stdout. It then opens a new file named * new and forces stdout to refer to it. Finally, it * restores stdout to its original state. */ #include <io.h> #include <stdlib.h> #include <stdio.h>
void main( void ) { int old; FILE *new;
old = _dup( 1 ); /* "old" now refers to "stdout" */ /* Note: file handle 1 == "stdout" */ if( old == -1 ) { perror( "_dup( 1 ) failure" ); exit( 1 ); } write( old, "This goes to stdout first\r\n", 27 ); if( ( new = fopen( "data", "w" ) ) == NULL ) { puts( "Can't open file 'data'\n" ); exit( 1 ); }
/* stdout now refers to file "data" */ if( -1 == _dup2( _fileno( new ), 1 ) ) { perror( "Can't _dup2 stdout" ); exit( 1 ); } puts( "This goes to file 'data'\r\n" );
/* Flush stdout stream buffer so it goes to correct file */ fflush( stdout ); fclose( new );
/* Restore original stdout */ _dup2( old, 1 ); puts( "This goes to stdout\n" ); puts( "The file 'data' contains:" ); system( "type data" ); } 自己的实例:
int old; FILE *new;
old = dup( 1 ); if( ( new = fopen( "/home/hy/0516/ilm/ilmsched/aaa.log", "w" ) ) == NULL ) { puts( "Can't open file 'data'\n" ); exit( -1 ); } if( -1 == dup2( fileno( new ), 1 ) ) { perror( "Can't _dup2 stdout" ); exit( 1 ); }
execl( "/home/hy/0516/ilm/ilmassess/ilmassess", "ilmassess", "/home/hy", "-mode", "both", "-logdir", "/home/hy/ilm/ilmassess/", "-logfile", "ilmassess.log", "-errfile", "ilmassess_err.log", "-parfile", "/home/hy/0516/ilm/ilmassess/ilmassess_option",NULL);
fflush( stdout ); fclose( new ); |
[挂载人]初学MPEG [审核人]初学MPEG 推荐 |
|
|
Please Login (or Sign Up) to leave a comment |