Redirect the output of the telnet to a file

Hi,

I am using cygwin.

Below is my script that reads all ip ports for iplist.txt and telnets to it.

(
file="iplist.txt"
while read line
do
echo $line
echo $(telnet $line)
done <"$file"
) > output2.txt
~

while the output2.txt gets the first echo but does not show the second echo with the telnet command.

If i remove the second echo with the telnet the output of the command prompts is good. So how can i direct that output to a file ?

First, perhaps try the >> to append
Second, perhaps try to do the >>myfile with each output desired

I tried with double ">>"

( file="iplist.txt" while read line do echo $(telnet $line) done <"$file" ) >> output2.txt

but the script completed immediately when it should take 30 mins as there are 200 ip ports. Also, did not see any output in the generated output2.txt file. Is my syntax incorrect ? Any solutions please ??