Solved

Using pipes

Posted on 2004-04-08
4
426 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: 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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
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 opening and reading files in the C programming language.
Suggested Courses

752 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