title: How to store console output for each while loop step in one text file using Ruby $stdout?
body: <p>Hi I want to store whole console out put generated by all steps of while loop using.
  I can store console output in one text file for first step of while loop but after this my loop is terminated.
  Code snippet is below:</p>
  
  <pre><code>while line = f.gets do
      puts "value: #{line}"
      newuri = a.to_s.gsub('fuzz',"#{line}")
      print "Attack Request:\n\n#{newuri}\n"
      nuri = URI.parse("#{newuri}")
      Net::HTTP.start(nuri.host, nuri.port) do |http|
      request = Net::HTTP::Get.new nuri.request_uri
      response = http.request request 
      puts "Response"
      puts response.body
              $stdout = File.new('out.txt','w')
      end
  end
  </code></pre>