I have the following 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
{
// ...
}
The problem is, the input/output of the execvp()
call is still the console, rather than the files. Clearly I am doing something wrong, what is the right way to do this?