Ah, yes... ARGV is not for input, it's for arguments.  I can see
how it's sort of a subtle distinction.  STDIN is where input from
pipes (|) and redirection (<) ends up.  STDOUT (usually where
puts and so on write to by default I'm pretty sure) gets redirected
with ">".

ARGV is for command-line arguments.

Try your original script with something like:

   % my_utility.rb some command line stuff

You'll get an array ["some", "command", "line", "stuff"]

        -glenn

Greg Willits wrote:
> On Dec 18, 2009, at 10:15 PM, Glenn Little wrote:
> 
>> If you meant what you typed and it wasn't a typo, the pipeline
>> is backwards.  Should be:
>>
>>  % head -n 1 file.txt | my_utility.rb
> 
> OK. Still, I see no values in ARGV -- which seeing the line above, it  
> would make sense. I'm no longer trying to pass an argument to  
> my_utility, so I must have to pick up the piped input in some other way.
> 
> So, back to Matt's input (no pun intended, ar-ar)...
> 
> Instead of ARGV I use STDIN.gets, and it works.
> 
> Thanks guys.
> 
> -- gw
> 
> 

-- 
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby

Reply via email to