Help with the ".times" command in ruby

Hey guys,

I’m trying to run a section of my ruby script 5000 times.
Can someone show me how to do this, as I have no programming
experience. Once I log into the BDI-3000 via Telnet, I just need
to loop the section of the script from the date stamp line to the end
of the script for 5000 times.

Here’s my script.

#!\ruby\bin\ruby.exe -w
require ‘strscan’
require ‘net/telnet’

$fileName = “Flash_Loop”
$outFile = File.new("…\\Temp\#{$fileName}.txt", “w”)

$outFile.puts “Flash loop to test the stability of flash chip after
multiple flashes.”

$dut_ip = “10.1.4.130”

Signal.trap(“INT”) do
puts “Received INT killing #{$$}”

end

tn = Net::Telnet.new(“Host” => $dut_ip, “Prompt” => /Core#0>/) {|str|
print str }

#######Date Stamp#########################################
date_result = IO.popen(“date /T”, “w+”)
buffer = date_result.readlines
puts buffer
$outFile.puts buffer
date_result.close
time_result = IO.popen(“time /T”, “w+”)
buffer = time_result.readlines
puts buffer
$outFile.puts buffer
time_result.close
result = tn.cmd(“unlock 0x50000000 0x20000 3”) {|str| print str
str
}
$outFile.puts result
result = tn.cmd(“erase 0x50000000 0x20000 3”) {|str| print str
str
}
$outFile.puts result
result = tn.cmd(“prog 0x50000000 redboot64.bin BIN”) {|str| print str
str
}
$outFile.puts result
result = tn.cmd(“verify”) {|str| print str
str
}
$outFile.puts result

$outFile.puts
“---------------------------------------------------------------------”

You can use the times method like this:

5000.times do

do some work

end

Regards,
Craig

Craig D. wrote:

You can use the times method like this:

5000.times do

do some work

end

Regards,
Craig

Thanks Craig,

I inserted your code and it works perfect.

-GHynson

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs