Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Using pipes

Posted on 2004-04-08
4
Medium Priority
?
434 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 750 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
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…
The goal of this video is to provide viewers with basic examples to understand and use structures 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.
Suggested Courses

916 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