The error I get in a dos-box is The system cannot find the path specified.
To produce the error you gave, I must do it this way: ruby a.rb < nul:
When you post something that depends upon a particular operating system, you
need to make that dependency clear.
indeed. that's what specifying cat and /dev/null does in and least four ways:
cat, the most ubiquitous of unix programs => *nix
/ as file separator => *nix
/dev file system => *nix
/dev/null device => *nix
It is reasonable to write a program that requires input. It is not
reasonable to expect a program that requires input to function properly when
you deliberately deprive it of input.
that's not what is happening. reading from /dev/null or nul is the same as
reading from an empty file. the key point i was illustrating, and the bug in
the program, is that is fails at eof regardless if input is given.
for example, if i run this from the shell and type 'ctrl-d' to signal end of
input (on unix)
harp:~ > cat a.rb
def chomper
until (xx = gets.chomp) == 'qq'
puts "hit me with a squirell!"
end
xx
end
puts chomper
harp:~ > ruby a.rb
a.rb:2:in `chomper': private method `chomp' called for nil:NilClass (NoMethodError)
from a.rb:8
running on an empty file does the same
harp:~ > touch empty
harp:~ > ruby a.rb < empty
a.rb:2:in `chomper': private method `chomp' called for nil:NilClass (NoMethodError)
from a.rb:8
as does running with some input
harp:~ > echo 42 > input
harp:~ > ruby a.rb < input
hit me with a squirell!
a.rb:2:in `chomper': private method `chomp' called for nil:NilClass (NoMethodError)
from a.rb:8
in fact, it cannot be made to work with any input
it's important, imho only perhaps, to show working code (best done by actually
showing a run) unless that code is noted to be un-tested. i make efforts to do
this for all examples i post:
http://groups.google.com/group/comp.lang.ruby/search?q=howard+cat+a.rb&start=0&scoring=d&
some probably find it anoying but i make too many mistakes otherwise.
kind regards.
-a
···
On Fri, 3 Feb 2006, William James wrote:
--
happiness is not something ready-made. it comes from your own actions.
- h.h. the 14th dali lama