title: In C how do you redirect stdin/stdout/stderr to files when making an execvp() or similar call?
body: <p>I have the following code:</p>
  
  <pre><code>pid_t pid = fork();
  if (pid == -1)
  {
      // ...
  }
  else if (pid == 0)
  {
      stdin = someopenfile;
      stdout = someotherfile;
      stderr = somethirdopenfile;
      execvp(args[0], args);
      // handle error ...
  }
  else
  {
      // ...
  }
  </code></pre>
  
  <p>The problem is, the input/output of the <code>execvp()</code> call is still the console, rather than the files. Clearly I am doing something wrong, what is the right way to do this?</p>