Public feed
#727549
#include "header.h"
int main(int argc, char *argv[])
{
/* initialization variables */
struct args these_args;
int fd_in;
int fd_out;
int pfd[2];
int status;
char buf[BUFSIZE];
char buf2[BUFSIZE];
int n_read;
int n_written;
these_args = parse_input(argc, argv);
fd_in = these_args.input_fd;
fd_out = these_args.output_fd;
if(fd_in != 0)
{
close(INPUT);
dup(fd_in);
}
if(fd_out != 1)
{
close(OUTPUT);
dup(fd_out);
}
n_read = read(fd_in, buf, BUFSIZE);
pipe(pfd);
if(fork() != 0)
{
if(fork() != 0) /* parent */
{
wait(&status);
wait(&status);
}
else /* child2 */
{
/* setup for writing */
close(pfd[0]);
close(OUTPUT);
if(dup(pfd[1]) == -1)
{
perror("dup2 failed");
}
close(pfd[1]);
execl("convert", "convert", buf, (char *) 0);
}
}
else { /* child1 */
/* setup for reading */
close(pfd[1]);
close(INPUT);
if(dup(pfd[0]) == -1)
{
perror("dup2 failed");
}
close(pfd[0]);
/* get stdin, which should be output from child2 */
scanf("%s", buf2);
execl("count", "count", buf2, (char *) 0);
}
close(fd_in);
close(fd_out);
}