I tried writing the whole thing in tcl, but came up against the problem of
not being able to see the status line info being displayed during the play
session. This means that there is no visual feedback if I change volume or
manually change where in the file I want to listen.
I came up with a solution of actually running mplayer from a bash script,
but calling a number of tcl scripts to get various bits of info used in
working out which files to play.
The actual code which invokes mplayer is:
mplayer "$filename" | tee "$logname"
This means that the stdout data is written simultaneously to both the
logfile and back to the terminal.
Is such functionality possible in a pure tcl environment?
TIA
Rob.
set logfile [open logfile w+]
set handle [open "|mplayer $filename" r]
fileevent $handle readable readmystuff
proc readmystuff {} {global handle logfile; set out [read $handle]; puts $out;
puts $logfile $out}
if {[catch {open "|mplayer $filename" r} pipefp]} {
error "$pipefp";# could use tk_essageBox in a GUI -- man tk_messageBox
}
fileevent $pipefp readable [list tee $pipefp SomeFunction]
proc tee {infp processFn} {
if {[gets $infp line] < 0} {
catch {close $infp}
} else {
puts $line
$processFn $line
}
}
proc SomeFunction {line} {
# Do whatever to $line
# Could be puts $somechanneltoalogfile "$line"
}
# if not in the GUI you need this.
vwait forever
>
> TIA
>
> Rob.
>
--
Robert Heller -- 978-544-6933
Deepwoods Software -- Download the Model Railroad System
http://www.deepsoft.com/ -- Binaries for Linux and MS-Windows
hel...@deepsoft.com -- http://www.deepsoft.com/ModelRailroadSystem/
Robert
I've looked at this code a few times and still do not understand your
use of 'vwait forever'. What has a GUI got to do with this code (as
per your comment)? Will the script not hang here until this is
released by changing value of the variable 'forever'? Or, more
likely, am I simply not understanding this aspect of the event
handling? I understand that vwait enables the event handling process,
but beyond this, I'm not sure ...
Rob.
Yeah, that was slightly awkward. His comment is true though unrelated
to your problem: the wish interpreter runs an implicit vwait when it
reaches the end of the script, for GUI handling.
But back to mplayer's output, if all you want is to emulate tee in
Tcl, you don't need vwait:
set ch [open "|mplayer ..." r]
set lf [open logfile a]
while {[gets $ch line]>=0} {
puts $line
puts $lf $line
}
but frankly I don't see the point. 'tee' is the best tee on earth, Tcl
won't challenge it :/
Maybe you can explain your goals ?
-Alex
Alex
Initially I had wanted to write the whole application in Tcl because I'm
comfortable with this language, but found that I couldn't do what I wanted
(at least that I knew then) so changed to using a bash script which calls
Tcl code to do the reading of the mplayer output (stdout) file and data
extraction from there.
The other factor is that if I want to port this to Windows then my use of
several Linux utilities makes the job significantly more complicated - not
that any porting is at all high on my list of priorities. The two original
responses mention using the 'fileevent' mechanism so I was trying to
understand how this code operates.
The overall goal of this project was to make it possible to have the system
automate the process of storing where I stopped listening to long podcasts
or vodcasts so I don't have to write the position down [and of course often
lose the reference :(] I mostly use mplayer so that was the logical media
player to use. Currently I'm happy to keep using 'tee' - as you said, it
does what it does really well!
BTW, the earlier postings be seen via the URL (on a single line):
http://groups.google.com.au/group/comp.lang.tcl/browse_frm/thread/b3e62524114b0894/59cc43939c2bd4b5
Rob.