Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion Writing a line based filter that exits when no input
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
Gordon Burditt  
View profile   Translate to Translated (View Original)
 More options 4 July, 08:32
Newsgroups: comp.unix.programmer
From: gordonb.cf...@burditt.org (Gordon Burditt)
Date: Sat, 04 Jul 2009 02:32:49 -0500
Local: Sat 4 July 2009 08:32
Subject: Re: Writing a line based filter that exits when no input

>Am writing a line-based  filter a la sed or tr. What I  would like it to
>do, however, is if there is no input at start-up, it should present some
>usage information and exit.

What is *NO INPUT*?  If stdin is closed (redirection <&- or 0<&-
), you'll get an error when you try to read from stdin.  It is
unlikely that anyone will do this.  Chances are most commands will
not react cleanly to being invoked with stdin closed if they
expect to use it.

Reading from the user's terminal is not "no input".  If you want
to detect if stdin is connected to the user's terminal or has been
redirected to another terminal, isatty() can detect this.

>E.g.,

>$ MyLineFilter < TextFile # OK

>$ Some Command | MyLineFilter # OK

>$ MyLineFilter
>MyLineFilter: Did not find any text to process.  Exiting.

>$ echo $?
>1

>$ MyLineFilter Command Line Args # Undecided what to do here ...

>Would appreciate some ideas on how to implement this.

>Currently, am writing the usage information to stderr (unconditionally),
>but the executable waits for input until it finds EOF.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google