Hi,
I want to implement the following and I haven't been able to implement it:
1) I would like to filter stdout output that comes from a batch file.
2) Basically I have a batch file for compiling our source code (takes about
10 minutes to run).
3) The batch file dumps its output to the stdout. I would like to filter the
output as it arrrives and to display only the messages I want.
4) How do I filter the messages as they arrive? I don't want to wait 10
minutes without seeing anything on the screen.
5) Do I use pipes for this? Do I use file events for this?
Thanks in advance,
Eyal Raab.
-----= Posted via Newsfeed.Com, Uncensored Usenet News =-----
http://www.newsfeed.com - The #1 Newsgroup Service in the World!
-----== 100,000 Groups! - 19 Servers! - Unlimited Download! =-----
Best to use file events, I think, because then your filter code gets
triggered
each time the output is flushed. If it is voluminous enough, you get a
fair response time that way.
Regards,
Arjen
O.K.
Let's say I'll be using file events. How do I run the batch file at the
start of the script
and then wait for the results? From what I know, if I use exec, than it will
wait for
the batch file to finish, which is not what I want.
I'm using Tcl 8.3.5 on a Win2k machine.
Thanks in advance,
Eyal Raab
"Arjen Markus" <arjen....@wldelft.nl> wrote in message
news:3E5498CA...@wldelft.nl...
The Wiki page <http://mini.net/tcl/3359> contains a worked out example
for managing a (Fortran) program (actually two-way). The Tcl side is
generic.
* Start the batchfile using [open "|mybatch.bat" "r"]
* Use [fconfigure] to make the channel unbuffered (at least from the Tcl
side)
* Register a read-handler. This reads the input line by line and spits
out
only those lines you want.
Regards,
Arjen
This'll get you started: it's a utility that works like you'd want
tail -f filename | grep regex
to work. Just change the pipe to your external process, and edit the
arg handling logic in main as appropriate.
#!/bin/sh
#\
exec tclsh "$0" ${1+"$@"}
proc main {argv0 argc argv} {
if {$argc != 2} {
puts "$argv0 <regex> <file>"
exit
}
foreach {regex filename} $argv break
if {![file readable $filename]} {
puts "can't read $filename"
exit
}
set pipe [open "| tail -f $filename" r]
fileevent $pipe readable [list inputhandler $pipe $regex]
vwait ::forever
}
proc inputhandler {channel regex} {
if {[gets $channel line] == -1} {
if {[eof $channel]} {
set ::forever now
}
} else {
if {[regexp -- $regex $line]} {
puts $line
}
}
}
main $argv0 $argc $argv
--
Glenn Jackman
NCF Sysadmin
gle...@ncf.ca