I have found a way to do this in shell script. May be it will help anyone sometime.
(sleep 1
echo "stdwh00";
sleep 1
echo "stdwh00";
sleep 3
echo ls
)| telnet
the sleep duration is accroding to the time your connection takes to connect to telnet the server.