Code Comments
Programming Forum and web based access to our favorite programming groups.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.
Post Follow-up to this messageIn 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 ***
Post Follow-up to this messageK.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.
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.