Linux redirect the stdout to a file
1: int save_out = dup(fileno(stdout));//backup stdout
2: int out = open("cout.log", O_RDWR|O_CREAT|O_APPEND, 0600);
3: int nRet;
4: fflush(stdout);
5: dup2(out, fileno(stdout));// redirect stdout to out
8: printf("Hello world!");
10: fflush(stdout);close(out);close(stdout);
11: dup2(save_out, fileno(stdout));//return the backup
12: close(save_out);
include the header file #include <fcntl.h>
Linux redirect the stdout to a file的更多相关文章
- Linux :: vi E212: Can't open file for writing
Linux :: vi E212: Can't open file for writing sysct1.conf 可能无写权限!查看方法:ls -lh /etc/sysct1.conf如果没有,则c ...
- No redirect found in host configuration file (C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet.config).
Configuration Error Description: An error occurred during the processing of a configuration file req ...
- Android开发:Android虚拟机启动错误Can't find 'Linux version ' string in kernel image file
Android启动出错,虚拟机报错信息如下: Starting emulator for AVD 'test' emulator: ERROR: Can't find 'Linux version ' ...
- linux局域网搭建yum仓库(本地(file)、网络(ftp、http))
linux局域网搭建yum仓库(本地(file).网络(ftp.http)) yum配置文件解释: [ ]:定义仓库,base为仓库的名字,可任意 name:仓库的简短文字描述 baseurl:仓库的 ...
- [svc]linux中的文件描述符(file descriptor)和文件
linux中的文件描述符(file descriptor)和文件 linux为了实现一切皆文件的设计哲学,不仅将数据抽象成了文件,也将一切操作和资源抽象成了文件,比如说硬件设备,socket,磁盘,进 ...
- Linux文件虚拟机系统只读Read-only file system的快速解决方法
问题描述:上周公司的私有云(底层架构是Openstack+KVM,目前稳定性还不够好,开发团队在改进中)一个计算节点挂掉,之后恢复后发现这个计算节点的所有Linux系统都变成只读了,复制文件提示:Re ...
- 自学Linux Shell3.6-文件查看命令file cat more less tail head
点击返回 自学Linux命令行与Shell脚本之路 3.6-文件查看命令file cat more less tail head 1.参看文件类型file 该命令用来识别文件类型,也可用来辨别一些文件 ...
- linux:nano 、cat和file
nano 在 Linux 下面编辑文件通常我们会直接使用专门的命令行编辑器比如(emacs,vim,nano),涉及 Linux 上的编辑器的内容比较多,且非常重要. nano 是 linux 的一款 ...
- linux sh文件提示 no such file or directory
Linux执行.sh文件,提示No such file or directory的问题的解决方法 12-06-28 16:59作者:love__coder Linux执行.sh文件,提示No such ...
随机推荐
- 添加删除一个controller
(文章是从我的个人主页上粘贴过来的,大家也可以访问我的主页 www.iwangzheng.com) rails generate controller Users rails destroy cont ...
- Sqli-LABS通关笔录-1
在第一个关卡当中还是学到些知识. 1.注释语句多试试其他的几个 2.不报错可能是前面的语句没有错误,union没有得到执行. http://127.0.0.1/sql/Less-1/index.php ...
- 异常:The absolute uri: http://www.springframework.org/security/tags cannot be resolved in either web.xml or the jar files deployed with this application
The absolute uri: http://www.springframework.org/security/tags cannot be resolved in either web.xml ...
- 如何实现SSH断开后 进程仍然在后台运行
1.nohup命令功能:不挂断地运行命令,忽略HUP信号.语法:nohup command & 实例:nohup ping www.google.com & 转自: http://bl ...
- Counting Bits
Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the ...
- Segment Tree Query I & II
Segment Tree Query I For an integer array (index from 0 to n-1, where n is the size of this array), ...
- 【leetcode】Palindrome Partitioning
Palindrome Partitioning Given a string s, partition s such that every substring of the partition is ...
- 利用cocostudio库函数 实现左右滑动的背包栏UI (cocos2d-x 2.2.0)
.h #ifndef __COMMON_COMPONENTS__ #define __COMMON_COMPONENTS__ #include "cocos2d.h" #inclu ...
- iOS7中都Bar的透明问题
/* New behavior on iOS 7. Default is YES. You may force an opaque background by setting the property ...
- oracle10G/11G官方下载地址集合 直接迅雷下载
Oracle Database 11g Release 2 (11.2.0.1.0) for Microsoft Windows (64-bit) http://download.oracle.c ...