Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

QUICK TUTORIAL: running programs in the background without expect

3 views
Skip to first unread message

Mark Lakata

unread,
Apr 26, 1996, 3:00:00 AM4/26/96
to

Many people have been asking about running an external program in the
background without losing control of the output and without "hanging"
the tcl/tk event loop. You can use expect, but there is a bit of
overhead this way, and you have to have expect rather than wish. My
example is to rewind a tape device.


label .a -textvariable status

# dumb way
set status "rewind"
exec mt -f /dev/nrmt0h rewind
set status "done"

# with expect
spawn mt -f /dev/nrmt0h rewind
set status "rewind"
expect eof
set status "done"

# best way
# To do it without expect is a bit different and more complicated, but I
# actually like it better. It allows you to spawn many jobs in
# the background, each with its own handler (i.e. you can rewind
# many tape drives simultaneously). This is a bit of a pain to do
# with expect

proc handler {t} {
global status
if [eof $t] {
set status "done"
close $t
return
}
set status [read $t]
}

set t [open "|mt -f /dev/nrmt0h rewind"]
set status "rewind"
fileevent $t readable "handler $t"

#--------------------
caveat. I know these methods working, but I haven't tested explicitly
tested these routines

good luck,
-Mark

0 new messages