This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

fileevent ??

Old posts that have not been replied to for several years.
Locked
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

fileevent ??

Post by Ofloo »

hmm ive read about file event its a binding that starts when a specific channel gets readable or writeable .. , but what about when a channel closes , i got a script that open exe "r+" after a few minutes when it ends (channel closes) i would like to trigger a trigger to perfom a script .. how would i do this .. ?? ive been looking true the manual and euhm can't find sutch thing . ? any one who can help me out ?
XplaiN but think of me as stupid
r
rolandguy
Voice
Posts: 25
Joined: Wed Aug 13, 2003 1:50 pm

Post by rolandguy »

if file readable and the data is NULL (""), that's the end of the events for that channel and the handler is removed.

basicly, if {$arg==""} {do_endscript} ;)

roland
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Use a utimer than cycles every few seconds.

It should check to see if the channel has gone "EOF" (using the "eof" command).

This will only trigger once the buffer is empty and you have tried to read the empty buffer.

If it is EOF, then you can call you own script, in other words, you are making your own small binding system.

Code: Select all


proc bind_eof {fp cmd} {
  if {[catch [list eof $fp]]} { error "Channel $fp non existant" }
  utimer 2 [list eof_check $fp $cmd]
}

proc eof_check {fp cmd} {
  if {[eof $fp]} {
    eval $cmd
  } else {
    if {[catch [list eof $fp]]} { error "Channel $fp no longer in existance" }
    utimer 2 [list eof_check $fp $cmd]
  }
}
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

If you want to set up a fileevent, use readable as roland suggests. But I'd caution that the if data = "" thing isn't necessarily true. If you're using gets, for instance, it will return "" if there is an incomplete line, or simply a blank line. A less fallible way to check for the channel closing is just to use the [eof] command like ppslim does in his code. To combine the two, it's something like this:

Code: Select all

set fp [open |blah.exe r+]
fconfigure $fp -blocking 0
fileevent $fp readable [list on_readable $fp]
proc on_readable {fp} {
  set len [gets $fp line]
  if {$len > 0} {
    # got a line, do whatever you want with it
  } elseif {[eof $fp]} {
    close $fp
    # program terminated
  }
  return 0
}
Not tested, of course :)
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

tnx for the scripts and i will test em sorry for the answer delay .. :/ was not home hehe for few days hehe so but ill test em for sur ;) tnx in advance this surtanly will give me new ideas ;)
XplaiN but think of me as stupid
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

# got a line, do whatever you want with it
# program terminated
what you exactly mean by this ? just curious ;) i mean is there where i put the info or is it just some info you added to make the code understandable .. ?
XplaiN but think of me as stupid
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

That's where you put your own code.
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

ah ok tnx
XplaiN but think of me as stupid
Locked