Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Writing a line based filter that exits when no input
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
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
 
Anand Hariharan  
View profile   Translate to Translated (View Original)
 More options 4 July, 07:10
Newsgroups: comp.unix.programmer
From: Anand Hariharan <znvygb.nanaq.unevun...@tznvy.pbz>
Date: Sat, 4 Jul 2009 06:10:12 +0000 (UTC)
Local: Sat 4 July 2009 07:10
Subject: 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.

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.

thanks,
- Anand


    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.
Barry Margolin  
View profile   Translate to Translated (View Original)
 More options 4 July, 07:23
Newsgroups: comp.unix.programmer
From: Barry Margolin <bar...@alum.mit.edu>
Date: Sat, 04 Jul 2009 02:23:18 -0400
Local: Sat 4 July 2009 07:23
Subject: Re: Writing a line based filter that exits when no input
In article <pan.2009.07.04.06.09...@tznvy.pbz>,
 Anand Hariharan <znvygb.nanaq.unevun...@tznvy.pbz> wrote:

In the third case, there IS input -- standard input is connected to the
terminal, and the user is supposed to type the input.

If you don't want to take input from the terminal, you can use:

if test -t
then echo $0: Did not find any text to process. Exiting. >&2
     exit 1
fi

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***


    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.
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.


    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.
Bjarni Juliusson  
View profile   Translate to Translated (View Original)
 More options 5 July, 00:10
Newsgroups: comp.unix.programmer
From: Bjarni Juliusson <bja...@update.uu.se>
Date: Sun, 05 Jul 2009 01:10:35 +0200
Local: Sun 5 July 2009 00:10
Subject: Re: Writing a line based filter that exits when no input

I guess what you mean is that if the stdin is a terminal, it should
print the usade information? That can then be accomplished by calling
isatty() on stdin, but I would say it would be better behaviour for the
program to accept input from the terminal as well, to allow users to
simply start the program and type text into it to test things easily or
do small amounts of work directly with minimum bother or copy and paste
text to the program. This is the way other unix filters work.

Bjarni
--

                        INFORMATION WANTS TO BE FREE


    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.
Anand Hariharan  
View profile   Translate to Translated (View Original)
 More options 7 July, 23:46
Newsgroups: comp.unix.programmer
From: Anand Hariharan <mailto.anand.hariha...@gmail.com>
Date: Tue, 7 Jul 2009 15:46:13 -0700 (PDT)
Local: Tues 7 July 2009 23:46
Subject: Re: Writing a line based filter that exits when no input
On Jul 4, 1:10 am, Anand Hariharan <znvygb.nanaq.unevun...@tznvy.pbz>
wrote:

Barry, Gordon and Bjarni,

Sincere thanks for responding to my post.

- Anand


    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.
End of messages
« Back to Discussions « Newer topic     Older topic »

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