The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to write to stdin of another program (program A -> [stdin]program B) vvaidyan UNIX for Dummies Questions & Answers 3 08-02-2008 05:21 PM
How to write to stdin of another program (program A -> [stdin]program B) vvaidyan High Level Programming 1 04-30-2008 01:44 PM
Capturing stdin domivv Shell Programming and Scripting 3 01-24-2008 04:30 PM
redirect STDIN prkfriryce Shell Programming and Scripting 4 01-04-2007 10:11 AM
echo with stdin systemsb Shell Programming and Scripting 6 09-28-2006 11:00 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-13-2005
marquis marquis is offline
Registered User
  
 

Join Date: Jan 2004
Posts: 12
stdin

hi,
how does a program know whether some data are available from stdin?
I would like to make a program which could read its data from stdin
and _if_there_is_nothing_at_stdin_ from a file which name is given
as an argument. If there is nothing in stdin and no filename is given as
argument, the program should quit immediatly (not wait.)

I'm on Linux with gcc (g++ in fact.)

TIA if any idea.
Samuel
  #2 (permalink)  
Old 04-14-2005
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
When opening the file for read, use the following:

open("<path/filename to open>", oflag|O_NONBLOCK,"mode if any");

The O_NONBLOCK will ensure that the reads do not block for data. read will return with -1 if there is no data to be read.

You can check for this and exit.
  #3 (permalink)  
Old 04-14-2005
marquis marquis is offline
Registered User
  
 

Join Date: Jan 2004
Posts: 12
thanks you !
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:57 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0