Solved

Using pipes

Posted on 2004-04-08
4
421 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

Why spend so long doing email signature updates?

Do you spend loads of your time carrying out email signature updates? Not very interesting are they? Don’t let signature updates get you down. Let Exclaimer Cloud - Signatures for Office 365 make managing email signatures a breeze.

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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now