Unix/Linux Go Back    

Homework & Coursework Questions Students must use and complete the template provided. If you do not use the template your post may be deleted! Special homework rules apply here.

How to create one's own pipe in one's own shell?

Homework & Coursework Questions

pipe, shell

Thread Tools Search this Thread Display Modes
Old Unix and Linux 01-09-2016   -   Original Discussion by AntoineCompagni
AntoineCompagni's Unix or Linux Image
AntoineCompagni AntoineCompagni is offline
Registered User
Join Date: Dec 2015
Last Activity: 9 January 2016, 5:48 AM EST
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Wrench How to create one's own pipe in one's own shell?

Good evening, I'm trying to do my own shell and I encountered some issues while creating it. Indeed when I try such a command I have

DAUPHINE> DAUPHINE> ls -l | grep terminal > fichier 
DAUPHINE> cat fichier

My shell is named DAUPHINE
Whereas I should have:


coppan12@b042-12:~$ ls -l | grep terminal > fichier coppan12@b042-12:~$ cat fichier 
-rwxr-xr-x 1 coppan12 student   13765 déc.  18 15:18 terminal

I did in a function called commande that activate a parsing function that looks for delimiters and creates an array mot with the other words:



It actually doesn't show the ls command
Have you any idea of how to fix it?

1. The problem statement, all variables and given/known data:

From the following parsing function, I had to create my own shell.
It was given from my teacher, I don't perfectly understand how it works but I did it but the pipe and the redirection with the pipe.

void parsing(){     int i=0;     int cmot=0;     while(1){         c = getchar();         if      (c == '\n') {symboleP = 0;return;}         else if (c == ';')  {symboleP = 1;return;}         else if (c == '&')  {symboleP = 2;return;}         else if (c == '<')  {symboleP = 3;return;}         else if (c == '>')  {symboleP = 4;return;}         else if (c == '|')  {symboleP = 5;return;}         else if (c == EOF)  {symboleP = 7;return;}         else if (c != ' ') {             symboleP = 10;             while(c != '\n' && !strchr(delimiteurs,c)){                 i=0;                 while(c != 32 ){                     if((c != '\n') && !strchr(delimiteurs,c)){                     mot[i]=c;i++;                     c=getchar();                     }                     else {break;}                 }                 break;             }             while(c == ' ')             {                 c=getchar();             }             ungetc(c,stdin);             mot[i]=0;             respP[cmot++]=strdup(mot);             fflush(stdout);             if(c == '\n' || strchr(delimiteurs,c))             {                 respP[cmot]=0;                 return;             }         }     }  }

Right then, there is my own function commande, which I created myself, I didn't shown the variables to make it lighter and shown the 0 case:

2. Relevant commands, code, scripts, algorithms:

simple UNIX commands
close, dup, fork, open...

3. The attempts at a solution (include all code and scripts):

I tried:

void commande () {     while(1){         if(execute==1){             if(symboleP==0){                 printf("DAUPHINE> ");             }                 for (j=0;j<10;j++){                 respP[j]=NULL;             }                         execute=0;                 background=0;         }         fflush(stdout);         parsing();         switch (symboleP) {// which are initialized above by the parsing             case 0 :                            // SYMBOLE : \n                 p=fork();                  if(p==0){                    //fils                     if(tube==1){//printf("\n\n\n");                               fich = open("fichtmp",O_RDONLY,0640);                         close(0); //fermeture clavier                         dup(fich); //fichier devient entrée 0                         execvp(respP[0], respP);                         close(fich); //fermeture fichier                           }                           else if(output==0 && input==0){        //pas de redirection                           printf("truc1");                         execvp(respP[0], respP);                            } ... other code over there ask me if needed ...

Okay, right actually the pipe doesn't work when I do

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Paris IX
Unix et programmation Unix
Sponsored Links

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Bash code to create named Pipe INHF Shell Programming and Scripting 5 01-30-2012 04:13 PM
Create a pipe to /dev/tty edgarvm Programming 2 11-10-2010 12:45 PM
Cannot create pipe necron SCO 6 10-01-2009 02:13 PM
Can't create more pipe uabcbac UNIX for Advanced & Expert Users 9 07-03-2002 11:33 AM

All times are GMT -4. The time now is 02:09 AM.