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

Filtering batch file output as it arrives

3 views
Skip to first unread message

Eyal Raab

unread,
Feb 20, 2003, 3:51:13 AM2/20/03
to
*** post for FREE via your newsreader at post.newsfeed.com ***

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! =-----

Arjen Markus

unread,
Feb 20, 2003, 3:58:50 AM2/20/03
to
Eyal Raab wrote:
>
> *** post for FREE via your newsreader at post.newsfeed.com ***
>
> 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?
>

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

Eyal Raab

unread,
Feb 20, 2003, 4:45:21 AM2/20/03
to
*** post for FREE via your newsreader at post.newsfeed.com ***

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...

Arjen Markus

unread,
Feb 20, 2003, 7:39:40 AM2/20/03
to
Eyal Raab wrote:
>
> *** post for FREE via your newsreader at post.newsfeed.com ***
>
> 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
>

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

Glenn Jackman

unread,
Feb 20, 2003, 11:21:52 AM2/20/03
to
Eyal Raab <ey...@corrigent.com> wrote:
> 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.

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

0 new messages