FILE * freopen ( const char * filename, const char * mode, FILE * stream );
在windows下控制台的标准输出设备是CON,在linux下面则用/dev/tty来显示当前终端,标准的应该是/dev/console,但个人试验只有tty的情况下
才能成功。设置了set-user-id并将user 改成root后依然无法使用console完成输出,具体原因有待考证。
在windows环境下:
#include <stdio.h> #include <stdlib.h> int main(int argc, char *agrv[]) { freopen("ExampleIn","r",stdint); freopen("ExampleOut","w",stdout); /* program */ freopen("CON","r",stdint); freopen("CON","w",stdout); printf("succeed!/n"); return 0; }
在linux环境下:
#include <stdio.h> #include <stdlib.h> int main(int argc, char *agrv[]) { freopen("ExampleIn","r",stdint); freopen("ExampleOut","w",stdout); /* program */ freopen("/dev/tty","r",stdint); freopen("/dev/tty","w",stdout); printf("succeed!/n"); return 0; }
转自:http://blog.csdn.net/lstjsuperman/article/details/6407409