Solved

Using pipes

Posted on 2004-04-08
4
424 Views
Last Modified: 2010-04-15
An user inputs a string from keyboard and transfers it  to the child using pipes, can anyone tell what commands to use
0
Comment
Question by:pokuri
  • 3
4 Comments
 
LVL 11

Expert Comment

by:avizit
ID: 10788763
Since you are talking bout "commands" I presume you are talking bout the pipes you use in a command line

if so the command to use is  "|" without the codes. Thats the pipe charcater which you can get by typing shift+\

e.g  say you have to count the number of words in a file

you can do

cat filename | wc -w

here your file content is piped to the word count program 'wc'
 what internally the system ( shell ? ) does is that it creates a pipe between your cat and wc command
effectively connecting the standard output of 'cat' to the standard input of 'wc'. The shell takes care of all the inter process communication or whatever

-abhijit
0
 
LVL 11

Accepted Solution

by:
avizit earned 250 total points
ID: 10788790
If on the other hand you are talking of pipes such as which are used for interprocess communication then you have to create a pipe with the pipe function

#include <unistd.h>

int pipe(int filedes[2])      

following I have copied from steven's Advanced programming in the unix environment


1.pipes are half duplex . data flows in only one direction
2. they can be used only between processes that have a common ancestor.

most of the time pipes are used as follows

you call pipe() and it returns two file descriptors . filedes[0] is opened for reading and filedes[2] is open for writing.
after that normally the program will fork and the child will close one of the descriptor and the parent will close the other
so henceforth the two processes can communicate with each other through the pipe ( in one direction only ) for bi directional comunication you need to open two pipes.

-abhijit
0
 
LVL 11

Expert Comment

by:avizit
ID: 10789431
Noted.

/abhijit/
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question