Xref: utzoo comp.unix.questions:31900 comp.unix.programmer:1971 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!dali.cs.montana.edu!milton!sumax!polari!rwing!eskimo!nanook From: nanook@eskimo.celestial.com (Robert Dinse) Newsgroups: comp.unix.questions,comp.unix.programmer Subject: Re: How do I tell if STDIN is a PIPE? Summary: How to tell if stdin is a pipe Message-ID: <653@eskimo.celestial.com> Date: 2 Jun 91 05:17:47 GMT References: <1991May26.172328.713@arizona.edu> <1991May30.101153.27842@thunder.mcrcim.mcgill.edu> Distribution: world,local Organization: ESKIMO NORTH (206) 367-3837 SEATTLE WA. Lines: 34 In article <1991May30.101153.27842@thunder.mcrcim.mcgill.edu>, mouse@thunder.mcrcim.mcgill.edu (der Mouse) writes: > In article <1991May26.172328.713@arizona.edu>, jjr@ace.ece.arizona.edu (Jeffrey J. Rodriguez) writes: > > > How do I tell whether stdin is coming from a pipe? > > Difficult. Under some systems, a "pipe" is not a distinguishable > thing; in particular, BSD implements pipes as connected pairs of > sockets, so a pipe appears identical to any other socket connection (of > the same address family, of course). Try: #include #include #include main() { struct stat s; if(fstat(0, &s)) { fprintf(stderr, "Can't stat stdin.\n"); exit(-1); } if(s.st_mode & S_IFIFO) printf("Stdin is a pipe.\n"); else printf("Stdin is not a pipe.\n"); exit(0); } This works on my machine but I don't have sockets so that may cloud the issue, but maybe this will be helpful.