i have created my own shell in linux. it works fine with commmands. Now I want to add pipes in it. i want to implement multiple piping in it. Can some one guide me how to do do? I havent used Linux. Iam new to it.
I have seen many source codes and sites but i am still not clear about the idea of executing commands having multiple pipes!
This is code i have implemented so far!
 #include <iostream>   
#include <sys/wait.h>   
#include <unistd.h>   
#include <string.h>    
#include <cstring>    
#include <sys/types.h>
using namespace std;
int main ()
{
    while (true){
    char * input;
    string insert;
    char * token;   
    char * parsed[9];   
    int count=0;
    char * cmd1[6];
    char * cmd2[6];
    cout<<"My Shell $";
    getline(cin,insert);          // take input from user
    input= new char [insert.size()+1];
    strcpy(input, insert.c_str());          
    for (int i=0; i<9; i++)
        parsed[i]=NULL;
    token=strtok(input, " ");
    while (token!=NULL)             // parse the input
    {
        parsed[count] = new char[strlen(token) + 1];
        strcpy(parsed[count++],token);
        token=strtok(NULL, " ");
    }
    delete input; 
    delete token;
    int j= count-1;
    int pipe_position[4]={0};
    int counter=0;
    for (int i=0; i<j; i++)                 // finding position of pipe 
    {
        if ((strcmp(parsed[i],"|"))==0)
            pipe_position[counter++]=i; 
    }
    bool pipe_exists=false;
    if (pipe_position[0]!=0)
    pipe_exists=true;
    if(pipe_exists==false)      // if there isnt any pipe in the command 
    {
        pid_t mypid=fork();  
        if (mypid==0)  
        {
            execlp (parsed[0],parsed[0],parsed[1],parsed[2],parsed[3],parsed[4], parsed[5],parsed[6],parsed[7],parsed[8],(char*) NULL); 
        }
        else if (mypid>0)
        {
            wait(NULL);   
            for(int i=0; i<9; i++)
                delete[]parsed[i]; 
        } 
    } 
    } //end of while 
}