The shortest route is via Mysore by road. Come upto Mysore by road then can board a train from Mysore to Bangalore or directly to Bangalore by road.
There may be a ban on traffic between Ooty and Mysore (Bandipur) in night. (Ban exists in Mysore-Wayanad route, I think in this route also.)
You can also come via Coimbatore, but it is big "U" turn. If you are opting this route as Ashok mentioned better to board the train from JTJ or KPD (If not yet booked the ticket from YPR).