Visit Our UNIX and Linux User Community

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

Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions How to create one's own pipe in one's own shell?
# 1  
Old 01-09-2016
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

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash code to create named Pipe

Guy's, I need help with creating a pipe, I found this code online but not exactly sure what different parts are doing. Will someone be able to help me with explaining what code is doing? Also what I want is to have everything the same directory. Meaning I am working in directory: I want... (5 Replies)
Discussion started by: INHF
5 Replies

2. Shell Programming and Scripting

Using Named pipe in shell script

Hi, I want to use a Named pipe to get input from a growing file for further processing. When I prototype this scenario using a while loop, the data is not written to the named pipe. This the script I use to get data into the Named pipe: #!/bin/ksh mkfifo pipe while (( n <= 10 )) do echo... (2 Replies)
Discussion started by: sudvishw
2 Replies

3. Programming

Create a pipe to /dev/tty

Hello everybody: I have a child process which reads a password from /dev/tty, as far as I know file descriptors for the child process can be seen by using lsof, so I want to connect to such device in order to send the password through a pipe, how could I do that? (2 Replies)
Discussion started by: edgarvm
2 Replies

4. Shell Programming and Scripting

Interactive shell through a pipe

I'm new to working with pipes, so I don't know whether the following is expected behaviour or a bug on the part of an application. Since Version 0.47, Inkscape provides a non-GUI interactive shell mode of operation. I am trying to time the program's performance in converting SVG files to PNG... (1 Reply)
Discussion started by: ccprog
1 Replies

5. SCO

Cannot create pipe

Hi, I'm new here, so please dont shoot me if I forgot something :) Some SCO box we've (our company) got recently from a new customer runs an app that hangs the entire box every once in a while. Today when an admin tried to start the db we got this error: $ dbstart dbstart: line 22: cannot... (6 Replies)
Discussion started by: necron
6 Replies

6. UNIX for Dummies Questions & Answers

how much we can pipe in shell prompt ?

Hi All experts, I was asked some questions of late & i was not aware of these. 1Q. how much we can pipe in shell prompt ?2Q. how many arguments we can pass in shell script & how to print that ? (eg, if i want to know what I passed in 11th Argument) ( for 3rd argument we can do echo $3, but I think... (7 Replies)
Discussion started by: adc22
7 Replies

7. Shell Programming and Scripting

Pipe data to shell script

Sorry about the noobish question but... How do I capture data thats piped to my script? For instance, ls -al | How do I access the output from ls -al in (3 Replies)
Discussion started by: tomjones07
3 Replies

8. UNIX for Advanced & Expert Users

Can't create more pipe

How can I change the maxnumber of pipes on my workstation? I'm running an EXPECT script that is suppose to start up 32 xterms. But after 18 opened xterm, I get this msg: - couldn't create pipe: too many open files regard, chris (9 Replies)
Discussion started by: uabcbac
9 Replies

9. UNIX Desktop Questions & Answers

How do I create desktop icons for the shell programs I create???

I am a bash shell programmer and I create programs on occasional basis. Now, I dont want my programs to be run by typing out its name at a command line. I want to make it as user friendly as possible. I want to create icons on the desktop so users can click on it. mind you, I said "desktop... (7 Replies)
Discussion started by: TRUEST
7 Replies

Featured Tech Videos