You must fully parse your command line before fork()
ing to start the child.
If a pipe operator is being used, you must set up the pipe before calling fork()
, so it is inherited.
In general you must also use close()
and often dup()
to make the pipe replace the forked process' stdin.
Continue reading up on these functions to "get" the big picture, or get a book which covers Unix I/O.