LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-15-2012, 09:15 AM   #1
Rohit_4739
Member
 
Registered: Oct 2010
Distribution: Red Hat
Posts: 228

Rep: Reputation: 9
Expect error - spawn id exp4 not open


Hello Guys,

First of all i would like to say that i am very new to Expect program so please forgive me if this might be a very stupid or basic question. I was writing my 2nd expect script following a tutorial on internet but i didn't execute successfully.
This is my script

Code:
#!/usr/bin/expect

set timeout 20
spawn "./echo.pl"
expect "hello"
send "Not matched entries : <$expect_out(buffer)> \n"
send "Mmatched entries <$expect_out(0,string)> \n"

interact
Here is the error i get when i execute

Code:
send: spawn id exp4 not open
    while executing
"send "Not matched entries : <$expect_out(buffer)> \n""
I did some googling to find out what this error means and how it might be fixed but i did not got any generic results which explained about the error. So i hope somebody here would definatly help me out.

Again please forgive me if it is a silly question because i have no so idea about Expect, i was reading through a tutorial and learning about it.
 
Old 12-16-2012, 09:29 PM   #2
cbtshare
Member
 
Registered: Jul 2009
Posts: 610

Rep: Reputation: 42
I know the website your following, but they have the code wrong.

1st) remove the interact , because the interact should follow some string, read the man page for more.

2nd) you need to set the expect buffers then use puts to echo them to the screen, thats why you get the error no matched entries found.

3rd) If you have expect(0,string) set and puts to print, then this will only work if some part of the string entered matches some part of what was expected.


so this should work.

Quote:
#!/usr/bin/expect
set timeout 20
spawn "./echo.sh"
expect "Hello"


set dif $expect_out(buffer)

puts "this is what you expexted $dif "
The above script will work if what was ran by the script echo.sh has the word "Hello" (case sensitive).If not then it will just echo what was not entered.
 
Old 12-17-2012, 01:08 AM   #3
Rohit_4739
Member
 
Registered: Oct 2010
Distribution: Red Hat
Posts: 228

Original Poster
Rep: Reputation: 9
Quote:
Originally Posted by cbtshare View Post
I know the website your following, but they have the code wrong.

1st) remove the interact , because the interact should follow some string, read the man page for more.

2nd) you need to set the expect buffers then use puts to echo them to the screen, thats why you get the error no matched entries found.

3rd) If you have expect(0,string) set and puts to print, then this will only work if some part of the string entered matches some part of what was expected.


so this should work.


The above script will work if what was ran by the script echo.sh has the word "Hello" (case sensitive).If not then it will just echo what was not entered.

Thanks Buddy, i will try.
 
Old 12-20-2012, 09:57 AM   #4
Rohit_4739
Member
 
Registered: Oct 2010
Distribution: Red Hat
Posts: 228

Original Poster
Rep: Reputation: 9
Quote:
Originally Posted by cbtshare View Post
I know the website your following, but they have the code wrong.

1st) remove the interact , because the interact should follow some string, read the man page for more.

2nd) you need to set the expect buffers then use puts to echo them to the screen, thats why you get the error no matched entries found.

3rd) If you have expect(0,string) set and puts to print, then this will only work if some part of the string entered matches some part of what was expected.


so this should work.


The above script will work if what was ran by the script echo.sh has the word "Hello" (case sensitive).If not then it will just echo what was not entered.

Hey cbtshare,

Can you direct me to some decent Expect tutorial, i did some googling but could not find what i was looking for. I do not want to go into very much details of the Excpect scipting language, but just want to have some basic knowledge so that i can use in some basic automation tasks.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
expect and spawn fails with ; figure20012 Linux - Newbie 7 09-12-2012 06:50 AM
Expect: spawn id expr4 not open gabes Linux - General 3 09-15-2011 01:07 PM
exp_i_parse_states: : file16 is not an expect channel - use spawn -open to convert pcs1976 Programming 0 03-15-2011 08:58 AM
send: spawn id exp1025 not open in tcl/expect bharatbsharma Programming 3 04-22-2010 03:04 AM
error in 6.13 binutils~ expect -c"spawn ls" sharmashikha Linux From Scratch 1 06-21-2005 12:53 PM


All times are GMT -5. The time now is 06:34 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration