launching an automated telnet session using dtterm

Hi ,
I have to write a shell script which would be invoked from a Java program. The job of this script would be to launch a telnet session i was using dtterm for the same and the expect command to automate that.

spawn dtterm -e telnet <server ip address>

expect "Username:"
send "$username\r"
expect "Password:"
send "$pass\r"
interact

The problem here ia m facing is that the above script which is executed from within a java program opens the dtterm as a child process over which i don't have any control in my java program.But i need to kill this tell session when my java programm is getting closed.

Could you tell me how to capture the process id of the this new dtterm process and send it back to my java code which would later kill this telnet session .

//rajeev