expect-string length problom

hi
i am writing an expect script to automate su command, my script goes like this...

#!/usr/local/bin/expect --
set password [lindex $argv 0]
set env_var [lindex $argv 1]
spawn su UNAME [lindex $argv 0]
expect "password:"
send "$password\r"
expect "env"
send "setenv PATHVAR $env_ver\r"
expect "env"
send "echo \$PATHVAR"
expect eof

arguments i am passing is password and $PATH variable. as PATH variable will be very long in length expect is not executing properly, its failing at "send "setenv PATHVAR $env_ver\r"" and not going forward..
any help on this will be appreciated..

Wrong way to go about this. Install and configure sudo and give a specific user(s) the NOPASSWD option. Here's just one thread to help you get started: Sudo help needed

It may be hanging as you have a typo in the variable name:

send "setenv PATHVAR $env_ver\r"

'env_ver' should be 'env_var'