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 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
expect log file

Posted by kannarv1 (kannarv1), 16 March 2006
hello all ,iam new to expect

i have a expect file and i have ceated a log file for debug info
log_file -a "$globalLogDir/debug.log"

but now in the same expect file i need to have an another log ..this log is primiraly for devlopment purpose where we need to have more debug statements where as other one is for users can i
create two log files like this  .

log_file -a "$globalLogDir/debug.log"
log_file -a "$globalLogDir/developer.log"

and in the function

for eg

proc dbgLog {.... } {
if {......} {
send_log "this is for bebug log"

send_log " this is for dev log"


how will the send_log will diff to which file iam writing the log info ...

hope iam clear ..

thanks much for any help

Posted by admin (Graham Ellis), 16 March 2006
Isn't the user log file going to produce far too much information for the user?   With a reuqirement like this, I would tend to use a log file file the developer / debugger, and a quite separate Tcl file (using commands like open and fputs) for the use information.

Posted by kannarv1 (kannarv1), 16 March 2006
thanks graham ,

but the problemis i already have alog file created and working which will be for dev i need to create a new log file jus for user applliication is i have expect at the backend an di construct xml  file and dump it to std out and my front end will parse those xml tags and display the user for eg :

if { [eval openCLI] } {

//for dev which has the ip address in this case in some cases we do have pwd also
dbglog $func " Failed to setup CLI session on OMCR-$ipAddr"

// for users which does nt ohave any info ..jus the message
errlog $func "failed to setup sesssion with router"

return -1

this is one of the function so the dbglog while write to file which has been already created which is for developmet purpose and err log is for the user.

this is the dbglog function
proc dbgLog { .... } {
thi swill write to dev  
send_log " ...."

now i need to write the same for errlog  which the user canmonitor ..since i have already created the file using log_file (dev log)send log will write all dbg info to that file not sure how to procced with debug log.

hope i am clear ..thanks much for ur help

Posted by kannarv1 (kannarv1), 16 March 2006
i guess puts will writ eto std output by default .i dont want to write to std output i wan to write directly to a file coz i write some other info into std out were i parse those std out thru xml parser ..i dont wan to mix these two .
Is there a way to do this .

thanks for any help

Posted by kannarv1 (kannarv1), 16 March 2006
hello all,

is there a way i can write directly to a file insted of writing to std out even if i use

log_user o

puts "$newfile ........."

log_user 1

log_user seems to disabl eonly the output from the spawned process ..puts still print in the std out and then writes to a file

Posted by admin (Graham Ellis), 17 March 2006
Don't use log_user or stuff like that unless you're looking for debug information - they're there to help the developer.  Expect is built on top of Tcl and so you have all the Tcl commands to hand too.  It's magic!

Here's a sample program that opens two output files and produces output to THREE places - stdout, a file I have chosen to caller shorter.txt and another file I have chosen to call longer.txt.

set full [open longer.txt w]
set summary [open shorter.txt w]

for {set k 1} {$k <= 50} {incr k} {
puts "iteration $k"
if {$k % 5 == 0} {puts $full "iteration $k by 5s"}
if {$k % 10 == 0} {puts $summary "iteration $k by 10s"}

If you want to produce log files that save your output onto the end of the previous log files, simply replace the w with an a in the open command ...

Posted by kannarv1 (kannarv1), 17 March 2006
Graham ! thanks a lot fo rthe reply ..but my concern is ..

this is how my application  works .

when a function executes succesfully in expect i form xml tags based on the ouput of the function and dump it in std out thru puts command .My front end Java appliation parses those xml tags and display sthe msg to user .

at the end of the function i have created a log file for developer thru send _log. which will have ifo abt variables pwd etc

now if i wan to create a new log file which i need to  dump general message ..when i use

puts by default it will dump  to std out and then dump to file .this will mess up xml tags and parser throws an exception.

is there any way i can write to a file with out dumping it in std out and writing directly to a file ..

thanks for all the help graham .iam preety new to expect i do not know some of the core func how expect work .


Posted by admin (Graham Ellis), 17 March 2006
I think the vital clue you need might be that the expect command sets up an array of return values called expect_out which contains the string that matches, and also all the other text that was received before that string - that's  in expect_out(buffer).  

Take what you get back in expect_out(buffer), use Tcl commands to manipulate it, and write what you need to save to file using the commands of my previous answer.  stdout is NOT involved, and nothing is logged to the screen if you have done a log_user 0

Posted by kannarv1 (kannarv1), 17 March 2006
thanks graham ..

i will try that way one mor econcern is after i manipulate the out buffer  when i use puts command to write to a file will not puts first dump to std out then write to a file ?


Posted by admin (Graham Ellis), 17 March 2006
No, if you tell it to write to a channel on which you've opened a file it will only write to that channel. It will not duplicate the output to stdout.

Posted by kannarv1 (kannarv1), 17 March 2006
thanks graham

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.

Comment: "Thanks!! Solved my problem :) ..."
Visitor Ranking 5.0 (5=excellent, 1=poor)

Comment by IDFly (published 2012-02-11)
Thanks!! Solved my problem :) [#31020]

You can Add a comment or ranking or edit your own comments

Average page ranking - 5.0

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho