Calling expect scripts from other expect scripts

Hi,

First, let me explain the issue I am trying to solve. We have a lot of expect scripts with the duplicated send/expect commands. So, I'd like to be able to extract the duplicated code into the common scripts that can be used by other scripts.

Below is my test where I am trying to call b.exp from a.exp:

a.exp
#!/usr/bin/env expect
#
set timeout 5
spawn $env(SHELL)
match_max 100000

send -- "./b.exp $spawn_id\r"

expect "bla"
expect eof
exit

b.exp
#!/usr/bin/env expect
#
set spawn_id [lrange $argv 0 0]
send -- "ls -al\r"
expect bla

I am passing the spawn_id into the b.exp script and then sending the "ls" command. The "ls" command does not output anything, so I understand that I can't pass just like that the handle to the process from one expect script to the other.

Could you suggest any other approach to solve my original issue or maybe there's actually a way to talk to the same process from the distinct expect scripts?

Thanks,
Seva