Skip to content

Instantly share code, notes, and snippets.

@clarkli86
Created November 15, 2013 07:29
Show Gist options
  • Save clarkli86/7480522 to your computer and use it in GitHub Desktop.
Save clarkli86/7480522 to your computer and use it in GitHub Desktop.
Redirect the standard out to a file and restore it later
int f = open(CONSOLE_LOG_CONSOLE, O_CREAT | O_RDWR, 0666);
int out = dup(1);
close(1);
dup2(f, 1);
// Do something
fsync(f);
close(f);
dup2(out, 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment