I am trying to telnet the port and want to get the output saved to the text file. I have looked and got two solutions but none of them are working for me through command prompt.
telnet 127.0.0.1 7000 -f output.txt
telnet 127.0.0.1 7000 >> output.txt
Also, checked this link for stdout and stderr with 1> and 2> respectively. Also tried to redirect 2 (stderr) to 1 (stdout) through 2>&1 as mentioned in this link.
File doesn't have any logs after running following code in batch file. But it stores the logs if it is able to telnet the port. But my requirement is to get the logs from cmd if telnet is unable to hit the connect as follows:
Connecting To 127.0.0.1...Could not open connection to the host, on port 7002: Connect failed
for port in 7000 7001 7002
do
start cmd.exe /k "telnet 127.0.0.1 $port -f C:\Users\rohit.bagjani\Desktop\result\telnetresult.txt"
done