UPDATE: managaed to get this working thanks to a similar thread, and some adjustments here and there.
So far in my program i:
-Fork a new process
inside the child, i exec a program entered by the user.
I want to send the ouput of this program, down a pipe ( pipe 1 ), rather than to stdout.
I then want to exec another program, sending it the information in pipe 1, and then outputting to stdout.
Code:
pid = fork();
if (pid == -1)
{
perror("dumbshell:fork");
exit(1);
}
/* child */
if (pid == 0)
{
/* dont need the read end */
close(fd[0]);
/* output will now be send down out pipe */
dup2(fd[1], STDOUT_FILENO);
execvp(clist->exe_path,clist->arg);
fprintf(stderr,"No such command: %s\n",clist->exe_path);
exit(1);
}
else
/* parent */
{
do
{
npid = wait(&stat);
//printf("Process %d exited with status %d\n",npid,stat);
}
while (npid != pid);
After the child exec's and exits, in the parent, i figure i create another child process, and exec in the newly created child.
How though, do i set it up so the new process reads from pipe 1, and outputs to stdout.
Hope I explained well enough for some to understand
Appreciate the help.