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 regexp output to another process

Posted by ntw (ntw), 5 April 2004
Hi,
I've any problem about expect with regular expression output . I want read a file (by open command) and use regexp capture any word in a variable. Then, that word use to run next command in the same script. Anybody ever seen the same problem. Plese suggest me or example script similar for this case.

In this example code, I want capture a word "lab2" instead by a variable $x  and run another command
$cat lab2
but nothing output occured ,when  uncomment "puts $line" . It had 2 lines output to monitor.

aaa     bbb     ccc     ddd     eee
fff        lab2    hhh     iii        jjj

----------------------------------------------------------------
Example code,

set file [open "/tmp/lab1.txt" "r"]
spawn -open $file
    while {[gets $file line] != -1} {
#   puts $line
     regexp "fff(.*)" $line
     set x $expect_out(buffer)
     send  cat $x\n
  }

--------------------------------------------------

/tmp/lab1.txt

aaa     bbb     ccc     ddd     eee
fff        lab2    hhh     iii        jjj
--------------------------------------------------


Thanks in advances,
ntw

Posted by admin (Graham Ellis), 6 April 2004
a) You're not doing anything with the results from your regexp - you're matching a pattern against $line and discaring the return (did it match - yes or no) and you're failing to capture the matched into another variable which is what I suspect you want to do.

b) Your regular expression will need to include something to match the spaces between the fff and the lab2, and it will need to include something to stop the matching after the lab2.

Suggestion - add a capture variable onto the regexp command, and add some puts statements directly after that command so that you can see what's happening and check your regular expression out.

Posted by ntw (ntw), 7 April 2004
Hi Graham Ellis,

Thank you for your reply. I'm a Expect beginner. Sometimes I ask easy questions. Can you give me axample script for read each line from file to regular expression expect to be output.

Regards,
ntw




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