LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Calling expect scripts from other expect scripts (https://www.linuxquestions.org/questions/linux-software-2/calling-expect-scripts-from-other-expect-scripts-632775/)

sevapopov 04-03-2008 02:10 PM

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

matthewg42 04-03-2008 05:21 PM

One approach is to make a library of functions which you would like to use in different scripts. See this document for more information.

sevapopov 04-03-2008 07:44 PM

Thank you for your suggestion. I was thinking about the same. Seems like the most proper solution for my requirements.

matthewg42 04-03-2008 09:33 PM

I think so. I've never tried controlling an expect script from within an expect script. I don't know how the pseudo terminal devices work... maybe there is a problem with this sort of nesting of pseudo ttys, I do not know.


All times are GMT -5. The time now is 02:03 AM.