Originally Posted by
CommonTater
Your posted code doesn't show that. Pleas post an update of your complete code, lets see where we're at...
This is my main code where i where i am doing the appending.
Code:
FILE *file = tmpfile();
FILE *logfile;
pid_t pid;
int pd[2];
pipe(pd);
pid = fork();
if(pid == -1){
fprintf(stderr, "Pipe Error");
exit(1);
}
// printf("1\n");
if(pid != 0){ // Parent Process writes
printf("In Parent\n");
while (fgets(input, sizeof(input), stdin)) {
printf("Parent received: %s", input);
strcpy(in,input); // saves previous command in
strcpy(in2,input); // saves full command in2
start = append(start, input);
stripcrlf(input);
parse(input);
printf("\n$ ");
if(strcmp(input,"history") == 0)
displayRecentCommands(start);
if(input[0] == '!')
getCommand(start, input, in);
time_t time;
fprintf(file, "%s", ctime(&time));
write(pd[1],input, sizeof(input));
printf("parent end\n");
}
}
else // Child Process
{
read(pd[0],temp,sizeof(temp));
while(strcmp(temp,"stop") != 0){ // 4 is ctrl+d ascii
printf("Im in the Child");
printf("Input Received: %s\n", temp);
read(pd[0],temp,sizeof(temp));
int i = 1;
fprintf(file, "%d. Command: %s", i++, temp);
}
// exec only returns if error
//fprintf(stderr, "an error with exec occured.");
// exit(1);
printf("child end\n");
}
char buffer[100];
int Char;
write(pd[1],"stop", sizeof("stop")); // send "stop" to end child process
logfile = fopen("logfile.txt","a");
Char = fread(buffer,sizeof(char),sizeof(buffer),file);
while(Char > 0){
fwrite(buffer,1,Char,logfile);
Char = fread(buffer,sizeof(char),sizeof(buffer),file);
}
fclose(file);
fclose(logfile);
savedata(start);
displaydata(start);
freedata(start);
return 0;
}