#include <unistd.h>
...
int saved_stdout;
...
/* Save current stdout for use later */
saved_stdout = dup(1);
dup2(my_temporary_stdout_fd, 1);
... do some work on your new stdout ...
/* Restore stdout */
dup2(saved_stdout, 1);
close(saved_stdout);
More Related Contents:
- Why does stdout need explicit flushing when redirected to file?
- What is the simplest way to write to stdout in binary mode?
- Does reading from stdin flush stdout?
- How to redirect the output back to the screen after freopen(“out.txt”, “a”, stdout)
- write() to stdout and printf output not interleaved?
- The difference between stdout and STDOUT_FILENO
- Writing to stdin and reading from stdout (UNIX/LINUX/C Programming)
- Scanf/Printf double variable C
- How to buffer stdout in memory and write it from a dedicated thread
- How could I temporary redirect stdout to a file in a C program?
- Why does printf() not print anything before sleep()?
- How can I implement ‘tee’ programmatically in C?
- Why the logical operators are not working as expected? [closed]
- what is the use of ‘return 0’ in C [duplicate]
- C programming: array not have any bound [duplicate]
- Where is the header file on Linux? Why can’t I find ? [duplicate]
- What is the behavior of printing NULL with printf’s %s specifier?
- Are the results of bitwise operations on signed integers defined?
- Is CHAR_BIT ever > 8?
- Assignment makes pointer from integer without cast
- n & (n-1) what does this expression do? [duplicate]
- Using MPI_Bcast for MPI communication
- Why can’t we initialize members inside a structure?
- Why does this memory address %fs:0x28 ( fs[0x28] ) have a random value?
- Why do most C developers use define instead of const? [duplicate]
- How to printf long long
- Keeping a global reference to the JNIEnv environment
- Check if a number is non zero using bitwise operators in C
- Why does auto a=1; compile in C?
- Linux function to get mount points