title: Using Dup2 to Redirect Input and Output
body: <p>I have been writing a Unix shell in C, and I am attempting to implement input and output redirection.  I have been using Dup2 for this and am able to make it so my output redirects to a file, and my input is redirected correctly as well.  However, after I'm done with that, how do I return to using Stdin and Stdout again? </p>
  
  <p>These are the pieces of code I run when redirection is required:</p>
  
  <p>In:</p>
  
  <pre><code>inFile = open(tok.infile, O_RDONLY, 0);
  inDup = dup2(inFile, STDIN_FILENO);
  close(inFile);
  </code></pre>
  
  <p>Out:</p>
  
  <pre><code>outFile = creat(tok.outfile, 0644);
  outDup = dup2(outFile, STDOUT_FILENO);
  close(outFile);
  </code></pre>