Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: small help in unix programing  (Read 7056 times)

0 Members and 1 Guest are viewing this topic.

naif

  • Guest
small help in unix programing
« on: December 17, 2004, 04:09:53 PM »
hi and good morning

i have a program that i wrote for unix shels and i want to modify it so it have more functionability only.

i need this program to ask the user to INPUT any 2 arguments he wants and then it executes this arguments, the program should use pipes.

here is my program that it should be modified, if it cannot be modified or difficult please help me to create a new program to do the same functions.

int main(void)
{
 int pfd[2];
 int pid;

 if (pipe(pfd) == -1)
 {
   perror("pipe failed");
   exit(1);
 }
 if ((pid = fork()) < 0)
 {
   perror("fork failed");
   exit(2);
 }
 if (pid == 0)
 {
   close(pfd[1]);
   dup2(pfd[0], 0);
   close(pfd[0]);
   execlp("wc", "wc",
          (char *) 0);
   perror("wc failed");
   exit(3);
 } else {
   close(pfd[0]);
   dup2(pfd[1], 1);
   close(pfd[1]);
   execlp("ls", "ls",
          (char *) 0);
   perror("ls failed");
   exit(4);
 }
 exit(0);
}