471,072 Members | 1,366 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,072 software developers and data experts.

question about writing c code supports pipe in

Hi,

How to write c code such that it supports pipe in?

i.e.,

echo "ABCD" | a.out

(how to write a c-code which generates the binaries a.out that can take the
pipe in input for further processing?)

thank you.

Carson
Nov 14 '05 #1
6 2335
Carson <ca****@ieee.org> scribbled the following:
Hi, How to write c code such that it supports pipe in? i.e., echo "ABCD" | a.out (how to write a c-code which generates the binaries a.out that can take the
pipe in input for further processing?)


Technically, pipes are an operating system feature and thus off-topic on
comp.lang.c.
However...
<OT>On most operating systems, for example all sensible Unices, these
kinds of pipes as you mention above are handled at stdio stream level.
This means that the first command's stdout is automatically connected to
the second program's stdin, and so on.
This means that you don't have to do *ANYTHING* to make your program
support pipe in. Just write your program using stdio streams like any C
textbook says, and the OS will automatically handle pipe in for you.
</OT>

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
Nov 14 '05 #2
Carson wrote:
Hi,

How to write c code such that it supports pipe in?

i.e.,

echo "ABCD" | a.out

(how to write a c-code which generates the binaries a.out that can take the
pipe in input for further processing?)

thank you.

Carson


read the stdin of `a.out'.

chok
Nov 14 '05 #3
Carson wrote:

Hi,

How to write c code such that it supports pipe in?

i.e.,

echo "ABCD" | a.out

(how to write a c-code which generates the binaries a.out that can take the
pipe in input for further processing?)


If your program gets its input from stdin, you don't have to do anything.
If your program doesn't use stdin, then you need to rewrite it so it does.

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+

Nov 14 '05 #4
Kenneth Brody wrote:
Carson wrote:

echo "ABCD" | a.out


If your program gets its input from stdin, you don't have to do anything.
If your program doesn't use stdin, then you need to rewrite it so it does.


Actually, wouldn't this break on non-Unix systems since stdin is opened
as a text stream? (I'm assuming a.out is binary data and thinking about
the potential end-of-line translations in other systems).

I don't intend to flame, only ask if I'm seeing it wrong.

--
Tiago
Nov 14 '05 #5
Carson wrote:
How to write c code such that it supports pipe in?

i.e.,

echo "ABCD" | a.out

(how to write a c-code which generates the binaries a.out
that can take the pipe in input for further processing?)


It sounds like you want to write a *filter*.
A filter accepts input from stdin and emits output to stdout.
The "pipe" is provide by your operating system shell.
You don't need to do anything special.
Just use stdin for input and stdout for output.
Nov 14 '05 #6
Tiago Quelhas <do*****@netcabo.pt> writes:
Kenneth Brody wrote:
Carson wrote:

echo "ABCD" | a.out

If your program gets its input from stdin, you don't have to do
anything.
If your program doesn't use stdin, then you need to rewrite it so it does.


Actually, wouldn't this break on non-Unix systems since stdin is
opened as a text stream? (I'm assuming a.out is binary data and
thinking about the potential end-of-line translations in other
systems).


a.out is the name of the executable program, not a data file. (It's
the default name of the executable generated by most Unix C compilers;
it was originally an abbreviation of "assembler output".)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Gary Robinson | last post: by
4 posts views Thread by Rajarshi Guha | last post: by
1 post views Thread by momena | last post: by
3 posts views Thread by EricR | last post: by
reply views Thread by Nick | last post: by
4 posts views Thread by Kevin Walzer | last post: by
5 posts views Thread by Mircea Pleteriu | last post: by
2 posts views Thread by MAx | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.