473,219 Members | 1,653 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,219 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 2409
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Gary Robinson | last post by:
In some code we're writing we're making an assumption, and I'd like to confirm that the assumption is valid. Suppose a signal arrives while a file is being written, and the signal handler...
4
by: Rajarshi Guha | last post by:
Hi, I'm having a little trouble when I read from a named pipe. I create a pipe by os.mkfifo('/tmp/mypipe') and then open it for reading with fin = open('/tmp/mypipe','r+')
1
by: momena | last post by:
Hi experts, I need to write a perl script that will be called from a series of executables chained thru pipes that read from STDIN and writes to STDOUT. The following code works fine under regular...
1
by: Michael Shestero | last post by:
Hello. General description of my knotty problem: I have a code (a function f) on standart C++ that perform some smart action. This code works as console application getting user input from...
3
by: EricR | last post by:
I am trying to use .NET to "tap into" a named pipe created by a non .NET 3rd party application. Specifically, the application is a table loading utility. It opens a named pipe and waits for input....
0
by: Nick | last post by:
hi,all I have a question about named pipe. How does the pipe server know the client closed the connection? We can refer the example for CreateNamedPipe() function in MSDN. In block mode, once...
4
by: Kevin Walzer | last post by:
I'm trying to structure a Python script that streams output over a pipe. Here is my code: import os cmd = os.popen('echo foo | sudo -S /usr/sbin/tcpdump -en1') cmd.read() This returns...
5
by: Mircea Pleteriu | last post by:
Hi, I have developed a a web application with ASP.NET 2.0 and VS 2005. My client wants to be delivered a .msi file that installs the app. My big problem is that the .msi also deploys the source...
2
by: MAx | last post by:
Hi guys, I am a c++ newbee and i am trying to write a file to a default printer. Please have a look at the code below and let me know if it'll work. I know that similar code in C will work. I...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.