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.
help with redirectioning output

Posted by pmnf (pmnf), 22 July 2004
I ppl im new to expect and to this forum. this as you can see my first post of many
My problem is the folowing.
i want to connect to a remote machine via telenet run a script name grab the output of the script and store it in a file.

In this moment i am doing the folowing
#!/usr/bin/expect -f
log_file -a MY_OUTPUT
set user xpto
set password xpto
set site
set VAR 1
set T 0
spawn telnet $site
while {$VAR>0} {
#puts $VAR
     expect {
           "login:" {
                 set rcvd $expect_out(buffer)
                 send "$user\r"
           "$user's Password:" {
                 send "pulso.2\r"
                 send "\n"
                 send  "cd nagios ;"
                 set rcvd $expect_out(buffer)
                 expect {
                       "bash#" {
                             send "./\r"
if {$T>3} exit
incr T

this is working but i think this isnt very good programing.
what i really want to do is to run the program like this
$ program.excpt >> AFILE &
"AFILE : contains the result of the
Any ideas

Posted by admin (Graham Ellis), 23 July 2004
I think you want to

a) start with

log_user 0

to turn off echo to stdout of all the text that comes back before you run your ./

b) add an extra expect after your

send ./

to cause expect to wait for the next shell prompt, then when you have it add a

puts $expect_out(buffer)

to send your output to stdout ... which your >> will cause to be redirected onto the end of the file at runtime.  You may need / want to puts an extra newline, datestamp, or header too so that you can easily analyse your logfile later on.


P.S.  Test it without the log_user line at first when you add the extra code in - otherwise if you have any bugs that cause the carefully choreographed exchange to fail, you won't know where they are.  

Posted by pmnf (pmnf), 23 July 2004
Thanks working allready

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: "Please describe how you did the redirection using a code ..."
Visitor Ranking 5.0 (5=excellent, 1=poor)

Comment by Sathya (published 2011-08-18)
Please describe how you did the redirection using a code snippet. [#3969]

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

Average page ranking - 5.0

© 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