D
David Warner
Greetings!
I need to write some C code that will decide between either reading from
stdin or take a file name from argv and process it.
The program needs to work like all of the typical unix utilities where
the file to process is either provided from a pipe/stream or argv.
Utilities like lp, tr, grep, etc.
So, when the command:
cat filename | grep -i > filename2
or
grep -i filename > filename2
executes, this acts like the programmtic interface i need.
I have tried everything I can think of from getc, getchar, read, gets,
etc. which all did not work. I test for EOF or NULL on the return values
and the program just hangs on a terminal read. So, the command:
cat filename | testprogram -dvalue
hangs on the reading from stdin and I never get to test for EOF.
What am i missing?
Do I need to set some type of fcntl flag and control the stdin flow
similar to a wait/nowait process?
BTW, i am compiling this on HP-UX B.11.00 Unix.
I need an answer ASAP!
Thanks in advance!
I need to write some C code that will decide between either reading from
stdin or take a file name from argv and process it.
The program needs to work like all of the typical unix utilities where
the file to process is either provided from a pipe/stream or argv.
Utilities like lp, tr, grep, etc.
So, when the command:
cat filename | grep -i > filename2
or
grep -i filename > filename2
executes, this acts like the programmtic interface i need.
I have tried everything I can think of from getc, getchar, read, gets,
etc. which all did not work. I test for EOF or NULL on the return values
and the program just hangs on a terminal read. So, the command:
cat filename | testprogram -dvalue
hangs on the reading from stdin and I never get to test for EOF.
What am i missing?
Do I need to set some type of fcntl flag and control the stdin flow
similar to a wait/nowait process?
BTW, i am compiling this on HP-UX B.11.00 Unix.
I need an answer ASAP!
Thanks in advance!