Skip to content

Instantly share code, notes, and snippets.

@huonw
Created March 18, 2013 10:11
Show Gist options
  • Save huonw/5186158 to your computer and use it in GitHub Desktop.
Save huonw/5186158 to your computer and use it in GitHub Desktop.
#include<stdio.h>
int main() {
puts("to terminal 1");
fflush(stdout);
int fd = dup(fileno(stdout));
freopen("out-file.txt", "w", stdout);
puts("to file");
fflush(stdout);
dup2(fd, fileno(stdout));
puts("to terminal 2");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment