Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 01-24-2009, 08:51 PM   #1
Senior Member
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 210Reputation: 210Reputation: 210
Detect pipe from running C program

I'm looking for a way to detect whether or not a program has been called from pipe, e.g.

whatever | my_program
versus simply just being exectuated directly:

Why? In the first case, I want to run the program non-interactively, and in the latter case I want to print out user-friendly messages. I've been thinking along the lines of some check I haven't yet found, like:
if( stream_buffer_is_not_empty() )
Any ideas?

Thanks to you!

Old 01-24-2009, 11:34 PM   #2
Senior Member
Registered: Oct 2003
Location: hopefully not here
Distribution: Gentoo
Posts: 2,038

Rep: Reputation: 51
#include <stdio.h>
#include <unistd.h>

int main (argc, argv)
  int argc;
  char** argv;
    if (isatty (STDIN_FILENO))
        printf ("Not a pipe.\n");
     else printf ("Its a pipe.\n");

     return 0;
The isatty function, as defined in unistd.h seems to work.


interactive, pipe, stream

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mimics of unix pipe program psandeepnair1985 Programming 1 03-20-2007 08:42 AM
Can't get user input when using a pipe to my C++ program ta0kira Programming 18 04-22-2006 01:53 PM
pipe for adding UI on console program okeyla Linux - Newbie 1 09-20-2005 09:36 PM
Program received signal SIGPIPE, Broken pipe. grupoapunte Programming 1 06-03-2005 06:49 AM
How to detect broken pipe in C (Linux)? alanwolfen Programming 4 02-23-2005 02:22 AM

All times are GMT -5. The time now is 11:07 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration