I have the following simple program that catenates infile to outfile
char *execArgs[] = { "cat", NULL};
int outfile = open("outfile", O_WRONLY | O_CREAT, 0644);
int infile = open("infile", O_RDONLY, 0);
dup2(outfile, STDOUT_FILENO);
dup2(infile, STDIN_FILENO);
close(outfile);
close(infile);
execvp(execArgs[0], execArgs);
Now, suppose the content of infile is
this is infile
and outfile is
this is outfile
After running the program, the content of outfile has an extra "e" at the end as such
this is infilee
Also, if the outfile is instead
this is outfile
this is outfile
It becomes
this is infilee
this is outfile
What is wrong?