stdin pipe to expect script

I want to feed a string to an expect script and have it stored in a variable and used as a password.
Needs to be invoked as:
echo "my_password" | ./myscript.exp

Anyone know how to do this?
Please see script example below:

#!/usr/bin/expect -f 
#### *** insert some command here to set $PASSWD to stdin ***
spawn ssh test@localhost
expect "*?password:*" { send "$PASSWD\n" }
expect "$ " 
send "exit\n"

Open in new window

Who is Participating?
amroxConnect With a Mentor Author Commented:
I found the solution, here it is for those who want to know:
while { !{eof stdin]} {
  gets stdin USERNAME
  gets stdin PASSWD
You'd better run your script as ./myscript.exp "my password". Then you can create $PASSWD very simple: set PASSWD [lindex $argv 0]
amroxAuthor Commented:
yes, I know how to use arguments, but this is not what I want.

Is it possible to do what I've asked?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.