How to check ARGF is empty or not in Ruby -


i want argf this.

# file.rb if argf.???   puts argf.read else   puts "no redirect." end  $ echo "hello world" | ruby file.rb hello world  $ ruby file.rb no redirect. 

i need without waiting user input. tried eof? or closed? doesn't help. ideas?

note misunderstood argf. please see comments below.

basically you'd examine #filename. 1 way is:

if argf.filename != "-"   puts argf.read else   puts "no redirect." end 

and more complete form:

#!/usr/bin/env ruby if argf.filename != "-" or (not stdin.tty? , not stdin.closed?)   puts argf.read else   puts "no redirect." end 

another:

#!/usr/bin/env ruby if not stdin.tty? , not stdin.closed?   puts stdin.read else   puts "no redirect." end 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -