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
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
Expect regexp output to another process

Posted by ntw (ntw), 5 April 2004
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



aaa     bbb     ccc     ddd     eee
fff        lab2    hhh     iii        jjj

Thanks in advances,

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.


This page is a thread posted to the opentalk forum at 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., 2022: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho