While trying to simulate the bash
command , I also need to write into a file called errors.log
any troubled output , if a given command from the user failed .
I've tried to enter a few wrong inputs , but the needed file is not updated as expected.
Here is the main
, it's a lot of code but I put the entire main , if there would be any doubt regarding each one of the variables . The actual action of main takes place with the forking , and
the calling to the method handleSonProcess
, which is down below , at the bottom of the code :
#define BUFFER 4096
#define BUFFER2 1024
#define RUN_FOREVER 1
#define ERROR_SIGN -1
#define TRUE 1
#define FALSE 0
When I run the code with the intput ls ddddx
, the output should be :
ls: cannot access ddddx: No such file or directory
and I want to write that output into the errors.log
file , but it doesn't get written .
What's wrong ?
Thanks
EDIT
errorFile = open("errors.log",O_WRONLY | O_TRUNC | O_CREAT,0600);
// open errors file
// if(errorFile <= 0)
{
sprintf(errorStr,"open: %s\n",strerror(errno));
write(errorFile,errorStr,strlen(errorStr));
fflush(stdout);
perror("open");
close(errorFile);
return 0;
}