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>
分享到:
相关推荐
-& - redirect stderr to stdout (Win32 only) All single-word options have three formats: -o - 'reverses' value of an option -o+ - set value to 'true' or 'on' -o- - set value to 'false' or 'off'
redirect STDERR to STDOUT (Win32 only) <br>All single-word options have three formats: <br> -o - 'reverses' value of an option -o+ - set value to 'true' or 'on' -o- - set value to 'false...
jad 最新版java反编译,最好的java反编译工具 Jad v1.5.8g. Usage: jad [option(s)] (s)> Options: -a - generate JVM instructions as comments (annotate) -af - output fully ... -& - redirect STDERR to STDOUT
java反编译工具 Jad accepts the following options: -a - annotate the output with JVM bytecodes -af - same as -a, but output fully qualified names when ... -& - redirect STDERR to STDOUT (Win32 only)
java反编译工具 Jad accepts the following options: -a - annotate the output with JVM bytecodes (default: off) -af - same as -a, but output fully qualified... -& - redirect STDERR to STDOUT (Win32 only)
stdout and stderr into a window(125KB)<END><br>94,GradientTitleBar.zip This article shows you how to give your Win95/NT4 modeless dialogs a Win98/W2K like gradient title bar.(42KB)<END><br>95,...