i've already inserted my script in my first post in this thread, but here is my script again:
#!/usr/bin/expect
set pass [lindex $argv 0]
set c [lindex $argv 1]
set command [string map {"_" " "} $c]
spawn sudo $command
expect "assword"
send "$pass\r"
expect eof
and yes,i need an script, because im using this script in my java code, and i can not execute commands as root in there without scripts, i need to execute commands such as "route add ... " or "route del ..." , and these commands need to be executed as root.
Firstly use clear password is very unscure!.you may must use just commands in shell without expect.or you can use sudo with NOPASSWD.
Even so i try to simple expect examples for your goal.