title: About stdout redirect and recover
body: <p>I want redirect stdout to /dev/null and then recover it for redirect it to stdout.txt, I wrote the code below</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main(void)
  {  
  
          fprintf(stderr, "stdout before: %d\n", stdout-&gt;_fileno);
  
          freopen("/dev/null", "w", stdout);
          printf("sdfsdf\n");
          freopen("/dev/tty", "w", stdout);
          printf("11111\n");
  
          fprintf(stderr, "stdout end: %d\n", stdout-&gt;_fileno);
  
          return 0;
  }
  </code></pre>
  
  <p>Build and test:</p>
  
  <pre><code>gcc 1.c -o 1
  ./1 &gt; stdout.txt
  </code></pre>
  
  <p>why output is:</p>
  
  <pre><code>stdout before: 1
  11111
  stdout end: 1
  </code></pre>
  
  <p>and <code>stdout.txt</code> is 0k.</p>
  
  <p>I wish the result is output  </p>
  
  <pre><code>stdout before: 1
  stdout end: 1
  </code></pre>
  
  <p>and the content of <code>stdout.txt</code> is 11111  </p>