How do I tell if STDIN is a PIPE?

Michael Pechner pechner at ddtg.com
Sat Jun 8 07:49:26 AEST 1991


In article <494 at ulticorp.UUCP> rick at ulticorp.UUCP (Rick Poleshuck) writes:
>In article <23190 at shlump.lkg.dec.com> lan_csse at netrix.nac.dec.com (CSSE LAN Test Account) writes:
>>In article <653 at eskimo.celestial.com> nanook at eskimo.celestial.com (Robert Dinse) writes:
>>>In article <1991May30.101153.27842 at thunder.mcrcim.mcgill.edu>, mouse at thunder.mcrcim.mcgill.edu (der Mouse) writes:
>>>> In article <1991May26.172328.713 at arizona.edu>, jjr at ace.ece.arizona.edu (Jeffrey J. Rodriguez) writes:
>>>> 
>>>> > How do I tell whether stdin is coming from a pipe?
>>>> 
>
>/* this looks real stupid but is quite portable */
>if ( lseek( 0, 0l, 0 ) < 0 && errno == ESPIPE )
>	puts( "stdin is from a pipe" );
>
>-- 
>		| Email - !uunet!ulticorp!ultixrs!rick
>Rick Poleshuck 	| Voice - (201) 887-9222 Ext. 755
>		| Mail  - The Ultimate Corporation, East Hanover, NJ 07936

This error is not just for pipes. It is for non_seekable 
devices in general.

-- 
pechner at ddtg.com (Michael Pechner)  | Pizza Probably The Worlds Most
DuPont Design Technologies Group          | Perfect Food.
Santa Clara, Ca                           | Carbo, Meat, Dairy, And Veggie 
                                          | All Food Groups In One.



More information about the Comp.unix.questions mailing list