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
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
On 09.07.2008, at 09:22, James C. wrote:
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
AFAIK that’s called I/O redirection.
ruby myprog.rb < ~/myfile.txt
$ ruby cat.rb < cat.rb
puts *ARGF
regards, 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 file
to
the programs standard input (stdin).
martin
On 09.07.2008, at 14:34, Martin B. 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
$ ruby cat.rb < cat.rb
puts *ARGF
regards, Sandor
Szücs
2008/7/11 Sandor Szücs [email protected]:
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
yet
another commandline option parser:
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.
On Jul 11, 2008, at 10:59 AM, James C. wrote:
–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.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs