title: How to spawn from a variable in Expect
body: <p>There are processes that take in a password partway through computation. I wish to insert a password at the start of the process, so I am trying to create a generic expect script that will spawn a process, then give it a password.</p>
  
  <p>This expect script takes in the password to enter and the process to spawn:</p>
  
  <pre><code>#!/usr/bin/expect
  
  set timeout 120
  
  # Get program to spawn and password to send
  set pswd [lindex $argv 0]
  set program [lindex $argv 1]
  
  spawn $program
  
  expect "Password:"
  send "$pswd\r"
  
  interact
  </code></pre>
  
  <p>This will be called from a bash function:</p>
  
  <pre><code>function vup {
      echo -n "Enter Password: "
      read -s pswd
      echo
      expectPassword.exp $pswd "vagrant up"
  }
  </code></pre>
  
  <p>But I get the error:</p>
  
  <pre><code>couldn't execute "vagrant up": no such file or directory
      while executing
  "spawn [join $program]"
  </code></pre>
  
  <p>This script seems to work when I use it on a program without arguments. But I'm not sure how to make it work for one with a variable number of arguments.</p>