After a lot of googling, I find the following code. It works.
#include <stdio.h>
void f() {
printf("stdout in f()");
}
main() {
int fd;
fpos_t pos;
printf("stdout, ");
// redriect
fflush(stdout);
fgetpos(stdout, &pos);
fd = dup(fileno(stdout));
freopen("stdout.out", "w", stdout);
f();
fflush(stdout);
dup2(fd, fileno(stdout));
close(fd);
clearerr(stdout);
fsetpos(stdout, &pos); /* for C9X */
printf("stdout again\n");
}
You can compile it with gcc. If you save it in a file with .cpp as extenstion name and compile the cpp file with g++, you need to include unistd.h. Add the following additional line.
#include <unistd.h>
分享到:
相关推荐
tensorflow model save and restore example
1、可以完好无损的备份你手机里的短信到SD卡,并且随时可以还原。 2、短信还原时,有重复检验功能,保证还原时已有的短信不会重复出现。 3、支持Android 2.2 更新日志: v5.800 - Dropbox support, needs Add-On ...
Save and Restore存储和恢复(7KB)
backup and restore
全面, 深入的讲解SqlServer数据库的各种备份和恢复策略和方案
rman backup and restore.
Clonezilla for Win 8 and 8.1 Backup and Restore
Be instructed on backup and restore techniques and principles Understand the importance of a fully implemented backup plan in SQL Server Agent Integrate backup and restore techniques into an ...
VERITAS NetBackup™ 5.1 Backup, Archive, and Restore Getting Started Guide for UNIX and Windows
NetBackup Backup, Archive, and Restore Getting Started Guide UNIX, Windows, and L inux Release 6.5
Informix V12.10--Backup and Restore Guide-285
The proposed control strategy can restore both voltage and frequency to their respective reference values while having accurate real power sharing, under a sufficient local stability condition ...
informix point in time table level restore
语言:English 备份和加密所有cookie,并在需要时解密和还原它们。 有新机器还是想重新安装操作系统? 但是不想重新登录到您的所有帐户吗? 使用此扩展程序备份您所有的珍贵cookie,并在以后还原它们。...
This book presents a systematic and unified approach for modern nonparametric treatment of missing and modified data via examples of density and hazard rate estimation, nonparametric regression, ...
system-tar-and-restore, 使用tar备份或者恢复系统,或者使用rsync进行传输 系统 Tar &还原关于分发包要求你可以做的 。备份模式还原/传输模式注释使用参数的示例 System包含两个bash脚本,主程序 star.sh 和一个。...
群晖restore工具
AIR(自动映像和还原)是dd / dc3dd的GUI前端,旨在轻松创建取证磁盘/分区映像。 支持MD5 / SHAx哈希,SCSI磁带驱动器,TCP / IP网络上的映像,拆分映像以及详细的会话日志记录。
tsm restore命令的详细解释! Therestorecommandobtainscopiesofbackupversionsofyourfiles from aTivoli®StorageManagerserver,orinside abackup set. Torestore files, specifythe directoriesorselectedfiles, ...