Solved

Using pipes

Posted on 2004-04-08
4
420 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
Comment Utility
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
Comment Utility
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
Comment Utility
Noted.

/abhijit/
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

763 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

10 Experts available now in Live!

Get 1:1 Help Now