|
Home > Archive > Unix Programming > September 2004 > Newbie question
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| K.M Jr 2004-09-29, 3:09 am |
| Hi group,
I got a pretty simple question -
Say I have a C program (executable as a.out)
What does this do - a.out < foo.txt
I believe I am piping foo.txt to a.out. But how is it available to
program i.e. how do I access foo.txt in the program ?
How is it different from - a.out foo.txt
Thanks.
| |
| Barry Margolin 2004-09-29, 3:09 am |
| In article <8228b1d2.0409290041.3a4b88c6@posting.google.com>,
opwv_pspl_test2@yahoo.com (K.M Jr) wrote:
> Hi group,
>
> I got a pretty simple question -
>
> Say I have a C program (executable as a.out)
> What does this do - a.out < foo.txt
>
> I believe I am piping foo.txt to a.out. But how is it available to
> program i.e. how do I access foo.txt in the program ?
No, there's no pipe -- a pipe is a connection between two processes.
The shell opens foo.txt and connects it to the process's standard input.
You access it by reading from stdin.
>
> How is it different from - a.out foo.txt
In this case, the program has to open the file itself.
By convention, most Unix programs that accept filename arguments will
automatically read from standard input if they don't get any filenames.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
| |
| Nils O. Selåsdal 2004-09-29, 8:09 pm |
| K.M Jr wrote:
> Hi group,
>
> I got a pretty simple question -
>
> Say I have a C program (executable as a.out)
> What does this do - a.out < foo.txt
The shell opens foo.txt as stdin for you.
> I believe I am piping foo.txt to a.out. But how is it available to
> program i.e. how do I access foo.txt in the program ?
>
> How is it different from - a.out foo.txt
The string foo.txt will be in argv[1], and you have to
open it if desired.
|
|
|
|
|