Piping data in on the command line

J

James Coglan

[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
 
M

Martin Boese

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
 
S

Sandor Szücs

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

James Coglan

2008/7/11 Sandor Sz=FCcs said:
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/jcoglan/oyster

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

ara.t.howard

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

http://github.com/jcoglan/oyster

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://codeforpeople.com/lib/ruby/main/main-2.8.1/README

http://codeforpeople.com/lib/ruby/main/main-2.8.1/samples/

gem install main


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

cheers.

a @ http://codeforpeople.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top