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 ...
随机推荐
- Java修改数组长度
java中没有关于修改数组长度的api,在此本人提供了修改数组长度的两个函数:arrayAddLength()和arrayReduceLength().详细见代码. [java] view plai ...
- 异常: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 ...
- 学习jquery mobile
学习jquery mobile的时间不是很长,在学习的过程当中也遇到了很多令人抓狂的问题,在网上搜索问题答案的时候发现,现在关于jquery mobile的文章还不是很多,所以,我也是一边学习,一边摸 ...
- 【消息队列MQ】各类MQ比较
目录(?)[-] RabbitMQ Redis ZeroMQ ActiveMQ JafkaKafka 目前业界有很多MQ产品,我们作如下对比: RabbitMQ 是使用Erlang编写的一个开源的消息 ...
- Java基础算法集50题
最近因为要准备实习,还有一个蓝桥杯的编程比赛,所以准备加强一下算法这块,然后百度了一下java基础算法,看到的都是那50套题,那就花了差不多三个晚自习的时间吧,大体看了一遍,做了其中的27道题,有一些 ...
- 【leetcode】Letter Combinations of a Phone Number
Letter Combinations of a Phone Number Given a digit string, return all possible letter combinations ...
- iOS UIDatePicker frame改变问题
这种方法不行: pickerCtl = UIDatePicker(frame:pickerFrame) 但是这种却行 pickerCtl = UIDatePicker() pickerCtl!.fra ...
- iOS 保存CGRect,CGPoint到NSArray'的方法
由于CGRect和CGPoint等对象是Struct,即结构体,不是继承于NSObject的,所以需要先用NSValue的方法,把他们转化成NSValue对象,之后就可以存入NSArray了! @in ...
- iOS 拍照中加入GPS和具体地理位置
最近有一个需求,要求用手机拍个照片,并切需要拍摄时间,拍摄gps,拍摄具体街道信息. 首先要感谢PhotoGPSdemo的作者,你可以到这里下载demo http://www.cocoachina.c ...
- Java for LeetCode 144 Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values. For example: Given binary t ...