From: tamouse mailing lists Date: 2013-03-01T12:03:09+09:00 Subject: Re: telnet - how to loop through commands listed in a file On Thu, Feb 28, 2013 at 4:55 PM, Bob Ford wrote: > I looked at my for loop and saw that I didn't even use the correct > variable in the loop... I change it but received the same error. > > I tried the mentioned: > File.open ("CMDs.txt").each > { | line | > telnet.cmd (line.gsub("\"","")) { ...} > } > But that failed with the following: > C:/Ruby Scripts/TelnetCMDs.rb:56: syntax error, unexpected tLPAREN_ARG, > expecting $end > telnet.cmd (line.gsub("\"","")) { |c| print c } File.open(..) passes a file handle to the block. If you want to spin through each line in a loop, try: File.readlines("CMDs.txt").each do |line| telnet.cmd(line.gsub("\"", "")) { ... } end To stay with .open: File.open("CMDs.txt") do |cmds| telnet.cmd(cmds.gets.gsub("\"", "")) { ... | end