On Jan 6, 2004, at 1:07 PM, david wrote:
[EMAIL PROTECTED] wrote:
Case 3. (this is the difficult case for me) the script is invoked
with no file and no pipe to it.  I would like the script to
end quietly, such as
test.input.source


Instead, it waits for input.


test.input.source
no command line args - switching to STDIN

and now it waits forever.

select / IO::Select is what you are looking for.
[..]

My compliments to David, as always.

The reason the code is 'waiting for ever' in
the case of having no STDIN is that it is in a
blocking IO Read on STDIN.

So since we have a better spec, I have updated the code
to show how the IO::Select could be used to gate
for the case that the code was called without
command line input, nor a current connection for STDIN.

<http://www.wetware.com/drieux/pbl/perlTrick/CommandLine/ file_or_stdin.plx>

Note all of the noisy 'print statements' are there
merely to show the transition of the logic of the code.


On Jan 6, 2004, at 12:53 PM, Steve Grazzini wrote:


On Jan 6, 2004, at 3:17 PM, [EMAIL PROTECTED] wrote:
Case 3. (this is the difficult case for me) the script is
invoked with no file and no pipe to it.  I would like the
script to end quietly

die usage() if @ARGV == 0 and -t;

You might not want to test if there is a controlling terminal - since that would prevent the pipe fitting from working unless there was a controlling terminal. A problem that will crop up when JoeBob opts wants to use the pipe fitting in their KSH script...

I didn't show you how to check for the pipe (-p) because
this should probably work, too:

% your-script <input.txt

We have Sooooo got to talk about your meds here...


8-)

To be honest, I had not thought about the idea of
'-p' even trying to test to see if it was a pipe
since it is-ish when one connects the pipe fittings
of the standard shell, or as you have done, the
express redirection of input...

[jeeves: 30:] wc -l funk*
      14 funk_env.plx
[jeeves: 31:] ./file* < funk*
no command line args - switching to STDIN
STDIN had 14 number of lines
we saw 14 number of lines
[jeeves: 32:]

The 'redirect in' of "<" simply is a way of changing
how STDIN is feed to the calling program by the shell.
It of course is dependent upon how the shell copes
with re-attaching STDIN|STDOUT combo's...


ciao drieux

---


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to