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:
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
I must admit that your question is a little unclear. I assume that you have a file with addresses, and you want to have a file with the responses received from these addresses.
Why are you trying to redefine
$stdout? Maybe all you need is toputsthe text directly to the"out.txt"file?Try this: (I have removed all “unimportant” details)
So, if I understood your problem correctly, you do usually do not need to “redefine” standard output, but you just have to put the data into the correct file. The method
putsexists also for opened files, and just “by default” writes to the standard output.In addition, I suggest using standard error instead standard output if you want some debugging information (not in this snippet of code – just in some other situations where it might be useful):
or
..whichever looks better for you. Both variable and the constant contain the same object.