Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Shell 

Waiting for keys

(Jul 2, 2015 09:12 AM)WOLGA Wrote:  @Annikke, @Exabyte

It might be just me, but I can't get
Code
@echo off
setlocal enabledelayedexpansion
echo %time%
for /l %%a in () do (
set /a a+=1
if !a!==500 goto ool
echo !a!
)
:ool
pause

to work as expected. Maybe you can be of some assistance.

This works on me as expected :/ probably something is wrong with your os.
Hrm, I thought it was working for me too, but actually something seems a bit funky..
It counts up to 499 as expected, then seems to jump to the label as expected, but then it should display "Press any key to continue . . ." and pressing a key should exit the script... but neither of these things happen. No message is displayed. Pressing a key has no effect.

Can you confirm this, Exabyte?
(Jul 3, 2015 01:39 AM)annikk.exe Wrote:  Hrm, I thought it was working for me too, but actually something seems a bit funky..
It counts up to 499 as expected, then seems to jump to the label as expected, but then it should display "Press any key to continue . . ." and pressing a key should exit the script... but neither of these things happen. No message is displayed. Pressing a key has no effect.

Can you confirm this, Exabyte?

I can confirm for you. It displays 499 followed by a console freeze. If you turn echo off and prompt $g then you'll see that the loop never actually stops, it's just stops displaying numbers once hitting 499. So the console isn't drawing a blank, it's just looping infinitely in the background.
Damn. There I was thinking I knew quite a bit about batch.
Turns out I know nothing. :>

If someone can explain this witchcraft, please feel free..
Why does the loop fail to end? Why does it crash? Why does it work correctly with a (1,1,10) style loop?

And, crucially, what does this tell us about the failure state of the original code?
That is correct, annikke, I simply cannot break out of this loop. Maybe there is something I haven't tried?

Some thoughts:

1. Why does it not goto ool?
2. Maybe it actually does, in fact, goto ool.
3. Why can you not break out of it?
4. If it does not break out of it, why does it stop displaying text?
5. Perhaps the number is still increasing, but is not being displayed?
why would you use 'for /l %%a in ()' when you can use 'for /l %%a in (1,1,1000000)' meaning that you can put a lot of zeroes back there.. and it wont bug out
That's a good question. The beginning of the answer is that it creates a different behaviour. A new behaviour is something that we might be able to exploit to create new functionality.
(Jul 4, 2015 02:04 PM)annikk.exe Wrote:  That's a good question. The beginning of the answer is that it creates a different behaviour. A new behaviour is something that we might be able to exploit to create new functionality.

It would depend on how limited this exploit actually is or isn't. From the way it's looking is that it has potential for threading as Qwerty demonstrated recently.
(Jul 4, 2015 01:08 PM)eXaByte Wrote:  why would you use 'for /l %%a in ()' when you can use 'for /l %%a in (1,1,1000000)' meaning that you can put a lot of zeroes back there.. and it wont bug out

First of all, that is limited and will not continue forever.
Secondly, I cannot break out of that, either.
Works for me.
Code
@echo off
setlocal enabledelayedexpansion
echo %time%
for /l %%a in (1,1,10000) do (
  set /a a+=1
  if !a! == 500 goto :ool
  echo !a!
)
:ool
pause

This time, it correctly exits the loop and displays "Press any key to continue . . ." as expected.
(Jul 9, 2015 12:28 AM)annikk.exe Wrote:  Works for me.
Code
@echo off
setlocal enabledelayedexpansion
echo %time%
for /l %%a in (1,1,10000) do (
  set /a a+=1
  if !a! == 500 goto :ool
  echo !a!
)
:ool
pause

This time, it correctly exits the loop and displays "Press any key to continue . . ." as expected.

I tried to exit the infinite loop (for /l %%a in ()) and its one tough nut to crack.
Spent an hour fiddling with it in vain, well almost, i found that ^&^ crashes cmd.
(Jul 9, 2015 03:38 AM)eXaByte Wrote:  I tried to exit the infinite loop (for /l %%a in ()) and its one tough nut to crack.
Spent an hour fiddling with it in vain, well almost, i found that ^&^ crashes cmd.

would it not echo & and just ask for More?
(Jul 9, 2015 03:46 AM)Recoome Wrote:  would it not echo & and just ask for More?

Why don't you try it ? :}