See also a better question, more specific, on this topic.
I\'ve just discovered expect, a tcl based scripting language for automating, among other things, telnet connect
As with my knowledge Swig would help you better in hooking up the the two languages. Let me know in case i was wrong
Swig