From: Chen Ge Date: 2010-04-12T09:42:45+09:00 Subject: Re: Using popen & grep Dan King wrote: > I'm relatively new to ruby and to practice I've put together the code > below - it's supposed take two arguments then apply it to a grep command > and display the output. Currently, nothing is outputted to the console. > Anyone see what I'm doing wrong, thanks. > > 1 #!/usr/bin/ruby > 2 > 3 results = IO.popen("grep -i #{ARGV[0]} #{ARGV[1]}", "r") > 4 while output = results.gets > 5 puts output > 6 end > 7 results.close cmd="grep -i #{ARGV[0]} #{ARGV[1]}" puts cmd results = IO.popen(cmd, "r") while output = results.gets puts output end results.close you should chech ARGV is correct. you can run cmd on console to see result,cheers! -- Posted via http://www.ruby-forum.com/.