Im implementing a shell in c, and im having a hard time redirecting the output of a command to a file. When i send the output to a file, it seems to work but the file does not open and when i run a ls -l it shows me the following:
---------x 1 warp staff 441 Nov 4 20:15 output.txt
This is some part of my code
pid = fork();
if(pid == 0)
{ /* child process */
if(redirFlag)
{
int fdRedir = open(redirectName, O_WRONLY | O_CREAT );
if( fdRedir < 0){
perror("Can't Open");
exit(1);
}
if(dup2(fdRedir, STDOUT_FILENO) == -1){
perror("dup2 failed");
exit(1);
}
}
execvp(supplement[0], supplement);
/* return only when exec fails */
perror("exec failed");
exit(-1);