
#include <unistd.h>
#include <stdio.h>

int main()
{

  FILE *newstdout;
  int fdstdout, fdnewstdout;
  newstdout = fopen("/tmp/xx.txt", "w");
  fdstdout = fileno(stdout);
  fdnewstdout = fileno(newstdout);
  dup2(fdnewstdout, fdstdout);
  fclose(newstdout);
  stdout = fdopen(fdstdout,"w");
  fprintf(stdout, "hi\n");
}
