
August 25th, 2004, 07:59 AM
|
|
Registered User
|
|
Join Date: Jul 2004
Posts: 16
Time spent in forums: 10 m 31 sec
Reputation Power: 0
|
|
|
conditions for single vs Pipe commands
I am trying to write a program that forks one child process to exeute single command and two chid processes when inpuit is pipe command "command1 | command 2.
While I execute the porgram with a.out ls -l watch.c
it gives me the right output.
But while executing a.out ls | wc it should not give me any o/p. but it shows 24 33 224 on the screen.
my problem is how can I make my program to check that it does not take pipe commands.
the code I am using is -
Code:
if(argc > 1)
{
switch(pid = fork()){
case -1:
fatal("fork failed");
break;
case 0:
printf("%s\n",argv[1]);
execvp(argv[1],&argv[1]);
fatal("couldn't execute Single command");
break;
default:
wait((int *)0);
printf(" Completed\n");
|