Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Expect - how to spawn a file read operation

Posted by neilvp (neilvp), 1 September 2006
Oh Great and Glorious Guru Graham your assistance please...

My challenge this week is to run a TCL script that waits for a router to boot, then tells it to multiple ping tests, collects the results, and then reboots router, repeat ad-infinitum.

This will be done over a serial port.

I have created a text file from the terminal interaction (i.e. having done it manually) and intend to use this as the source for testing the script before running live. i.e. read a line from this text file and use that as if it had come from the serial port.

The question is, how do I spawn this 'read a line from the file' so that Expect can use it?
..or should I try something different

I am running the current ActiveState releases under Windoze XP.

Your hints, tips, help and assistance, is, as ever, very much appreciated.

Neil

Posted by admin (Graham Ellis), 1 September 2006
On unix / linux,I would spawn a cat command.  Using the same logic on XP, I guess you would spawn a type command; not sure if that logic's going to work, but at least it's somewhere straightforward to start trying it out and, after all, you are only looking for a solution for testing purposes  

Posted by neilvp (neilvp), 1 September 2006
Thanks Graham.

This did not work but having caught the error I am puzzled as to the real reason...

Unfortunately I cannot figure out how to attach a screen shot to this mail ...

As you can see from the code, prior to my trying to spawn I check that the file exists, why do I do this (apart from good programming of course) is because the reason that is reported for the spawn failing is  'The system cannot find the file specified'

However, the file does exist in the same pwd and the 'file exists ' check supports this.

Any ideas as to why the 'spawn type' cannot find the file?

Thanks

Neil


package require Expect

set FileToRead test_file_1.txt

puts "File To Read is $FileToRead\r"


if { [file exists $FileToRead] } \
{
   puts "$FileToRead exists\r"
} else \
{
   puts "$FileToRead does not exist\r"
}    

if [catch {spawn type $FileToRead}  reason]\
{
   puts "Failed to spawn\r"
   puts "Reason $reason\r"
} else {
   puts "spawned"    
}    
   
  puts "Ending Program"



Posted by neilvp (neilvp), 1 September 2006
Doh!

It is of course the 'TYPE.EXE' it cannot find. To make matters worse type.exe (or type.com) no longer exists as a standalone program within XP, it is, I am told, built into the DOS shell which is why that test worked and I consequently thought the spawn could not find the target file.

Any other suggestions?
(Running cygwin is not an option - sorry)

Neil



Posted by neilvp (neilvp), 1 September 2006
Courtesy of those very nice people at sourceforge I found a cat utility for Windoze.

http://unxutils.sourceforge.net/

That certainly did what I thought I wanted but it has given me other problems to solve now... like how can I get it to do it one line at a time (or get the expect to loop)?

Can I do something like

while {stdout <> eof} {
expect {
              test1  { action1}
              test2  {action2}
            }
}

And I thought it such a straight forward task

Thanks

Neil

Posted by admin (Graham Ellis), 1 September 2006
You can do

while 1 {
     expect ...

      }

and have an eof option on your expect.



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho