LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-03-2008, 02:10 PM   #1
sevapopov
LQ Newbie
 
Registered: Apr 2008
Posts: 2

Rep: Reputation: 0
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
 
Old 04-03-2008, 05:21 PM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
One approach is to make a library of functions which you would like to use in different scripts. See this document for more information.
 
Old 04-03-2008, 07:44 PM   #3
sevapopov
LQ Newbie
 
Registered: Apr 2008
Posts: 2

Original Poster
Rep: Reputation: 0
Thank you for your suggestion. I was thinking about the same. Seems like the most proper solution for my requirements.
 
Old 04-03-2008, 09:33 PM   #4
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with BASH-scripts and EXPECT ElFredrico Linux - General 17 05-17-2012 11:51 PM
Calling external scripts swampdog2002 Slackware 4 01-31-2007 01:54 PM
Trouble calling 'expect' from bash raypen Linux - Software 1 06-01-2006 08:05 PM
expect scripts and cron banderson Linux - Software 8 05-27-2005 04:44 AM
using expect scripts for remote admin jmr71769 Linux - General 3 01-21-2004 01:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration