Linux 壳体中的管道

Linux 壳体中的管道,linux,shell,Linux,Shell,我已经在linux中创建了自己的shell。它可以与命令一起工作。现在我想在其中添加管道。我想在其中实现多个管道。有人能指导我怎么做吗?我没有用过Linux。我对它不熟悉 我看过很多源代码和站点,但我仍然不清楚使用多个管道执行命令的想法 这是迄今为止我已经实现的代码 #include <iostream> #include <sys/wait.h> #include <unistd.h> #include <string.h>

我已经在linux中创建了自己的shell。它可以与命令一起工作。现在我想在其中添加管道。我想在其中实现多个管道。有人能指导我怎么做吗?我没有用过Linux。我对它不熟悉

我看过很多源代码和站点,但我仍然不清楚使用多个管道执行命令的想法

这是迄今为止我已经实现的代码

 #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 
}
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
int main()
{
while(true){
字符*输入;
插入字符串;
字符*令牌;
字符*已解析[9];
整数计数=0;
char*cmd1[6];
char*cmd2[6];

coutcheck out the popen system call(man-popen)我想通过更改stdin和stdout来通过文件描述符来完成