[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Piping data in on the command line

James Coglan

7/9/2008 7:22:00 AM

[Note: parts of this message were removed to make it a legal post.]

Hello all,

I know you can get command line args using ARGV, but is there a way to use
the '<' operator to pipe data into your program, as in

ruby myprog.rb < ~/myfile.txt

--
James Coglan
http://github.c...

5 Answers

Sandor Szücs

7/9/2008 9:53:00 AM

0


On 09.07.2008, at 09:22, James Coglan wrote:

> I know you can get command line args using ARGV, but is there a way =20=

> to use
> the '<' operator to pipe data into your program, as in

AFAIK that's called I/O redirection.

> ruby myprog.rb < ~/myfile.txt

$ ruby cat.rb < cat.rb
puts *ARGF


regards, Sandor Sz=FCcs
--




Martin Boese

7/9/2008 12:34:00 PM

0

Just read the IO $stdin, like:

$stdin.each { |line| puts "Found: #{line}" }

The < "operator" is a shell feature that will pass the content of a file to
the programs standard input (stdin).

martin



On Wednesday 09 July 2008 08:22:15 James Coglan wrote:
> Hello all,
>
> I know you can get command line args using ARGV, but is there a way to use
> the '<' operator to pipe data into your program, as in
>
> ruby myprog.rb < ~/myfile.txt



Sandor Szücs

7/11/2008 4:46:00 PM

0


On 09.07.2008, at 14:34, Martin Boese wrote:

> Just read the IO $stdin, like:
>
> $stdin.each { |line| puts "Found: #{line}" }
>
> The < "operator" is a shell feature that will pass the content of a =20=

> file to
> the programs standard input (stdin).


Maybe that's more readable, but my point wasn't the shell feature < .
cat.rb has one line:
puts *ARGF

$ ruby cat.rb < cat.rb
puts *ARGF


regards, Sandor Sz=FCcs
--




James Coglan

7/11/2008 5:00:00 PM

0

2008/7/11 Sandor Sz=FCcs <sandor.szuecs@fu-berlin.de>:

>
> On 09.07.2008, at 14:34, Martin Boese wrote:
>
> Just read the IO $stdin, like:
>>
>> $stdin.each { |line| puts "Found: #{line}" }
>>
>> The < "operator" is a shell feature that will pass the content of a file
>> to
>> the programs standard input (stdin).
>>
>
>
> Maybe that's more readable, but my point wasn't the shell feature < .
> cat.rb has one line:
> puts *ARGF



Thank you both. If anyone is the least bit interested I'm writing myself ye=
t
another commandline option parser:

http://github.com/jcog...

It's inspired by trollop, but it has some more option types and is more
easily extensible, automates a few extra things (like recognizing
--no-verbose if you've got a --verbose option for example) and it generates
slightly nicer (more man-page-like) help text.

ara.t.howard

7/11/2008 6:09:00 PM

0


On Jul 11, 2008, at 10:59 AM, James Coglan wrote:

>
> Thank you both. If anyone is the least bit interested I'm writing
> myself yet
> another commandline option parser:
>
> http://github.com/jcog...
>
> It's inspired by trollop, but it has some more option types and is
> more
> easily extensible, automates a few extra things (like recognizing
> --no-verbose if you've got a --verbose option for example) and it
> generates
> slightly nicer (more man-page-like) help text.


you may be interested in

http://codeforp...lib/ruby/main/main-2....

http://codeforp...lib/ruby/main/main-2.8....

gem install main


the whole concept is to obviate the notion of ever parsing options

cheers.

a @ http://codeforp...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama