Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

ON CLOSE, GOTO, and X-ing the console

May
13,211
180
If this BTM is running and I close the console via the "X", I hear the beep.
Code:
on close beep
do forever ( delay 1 )
If this BTM is running and I close the console via the "X", I do not hear the beep.
Code:
on close goto done
do forever ( delay 1 )
:done
beep
What's up with that? I'd really like to be able to rely on my ON CLOSE mechanism.

If I do this and X the console, I get a full 5 seconds before the batch file stops and the console closes.
Code:
on close do forever ( delay 1 )
do forever ( echo %_do_loop & delay 1 )
But this way I get no time at all.
Code:
on close goto done
do forever ( echo %_do_loop & delay 1 )
:done
do forever ( delay 1 )
 
There is no "duration protection" for a GOTO in an ON CLOSE -- once you've moved the execution pointer, TCC drops out of the ON handler and returns to the batch parser to execute the next line. And the batch parser then notices that Windows is shutting down the session, so everything exits.

If you want to do something in an ON CLOSE, you have to do it within the ON CLOSE statement.
 
If you want to do something in an ON CLOSE, you have to do it within the ON CLOSE statement.

I wanted to do quite a bit ON CLOSE. Fortunately, a multiline command works fine.
Code:
on close (
   delay 1
   echo foo
   delay 1
   echo bar
   delay 1)
do forever ( echo %_do_loop & delay 1 )
 
If you're still using a 32-bit version of Windows, you're going to be restricted to less than 2Gb in your ON CLOSE statement. Which should prove adequate in most cases.

And Windows is going to kill you after ~5 seconds anyway, no matter how much you really wanted to do.
It's not time or resource consuming stuff, just several lines. Hee-hee ... 2GB is ALL my memory. And it's plenty. I rarely go below 1GB free, even after weeks/months of uptime.
 
Back
Top
[FOX] Ultimate Translator
Translate