I need to create a new process to run the xxx program, load the xxx program, send 'xxx' the data read from a pipe, but I'm getting this error, "Error: could not read from stdin" whenever I try to compile.
pid_t pid;
pid = fork();
int fd[2];
int ret;
ret = pipe(fd);
if (ret == -1)
{
perror("pipe failed");
exit(1);
}
if (pid == -1)
{
perror("fork failed");
exit(1);
}
else if (pid == 0) //Child
{
char buff[10];
int validate;
close(fd[1]);
dup2(fd[0], STDIN_FILENO);
close(fd[0]);
read(STDIN_FILENO, buff, sizeof(buff));
xxx = execlp("./xxx", "./xxx", NULL); //run xxx
exit(validate);
}
else //Parent //WRITE STDIN TO PIPE
{
close(fd[0]);
//writes data to pipe
close(fd[1]);
Help would be much appreciated!