html - Echoing a URL in Batch -


edit: variable wasn't defined properly. have no idea why have found workaround this:

there 6 pages needed. have created 7th page instantly return page 1. , %htmlnxtpg% variable not needed anymore.


i trying create batch file spit out html file user won't need understanding of html make site.

the site needs "live" have iframes redirecting each other using

<body onload="timer=settimeout(function(){ window.location='file:///c:/users/myuser/dropbox/pagemdb/sources/page/page_%htmlnxtpg%.html';}, %htmllen%)" style="background:#408cbd"> 

(this url temporary run locally now)

and there variable mentioned in url named %htmlnxtpg% echo command ignoring it. not outputting there leading browser having 404. defining htmlnxtpg variable using

delayedexpansion on during defining of variable , off when using it.

edit: code horribly made , has been fixed comment , answer (@stephan , @mofi)

if htmlpgnr==1 set /a htmlnxtpg=2  if htmlpgnr==2 set /a htmlnxtpg=3 if htmlpgnr==3 set /a htmlnxtpg=4 if htmlpgnr==4 set /a htmlnxtpg=5 if htmlpgnr==5 set /a htmlnxtpg=6 if htmlpgnr==6 set /a htmlnxtpg=1 

the result

file:///c:/users/myuser/dropbox/netpage/sources/page/page_.html 

while should

file:///c:/users/myuser/dropbox/netpage/sources/page/page_1.html 

and 1 outcome of variable

the echo line should output body tag:

echo ^<body onload="timer=settimeout(function(){ window.location='file:///c:/users/myuser/dropbox/netpage/sources/page/page_%htmlnxtpg%.html';}, %htmllen%)" style="background:#408cbd"^>>>sources/page/page_%htmlpgnr%.html 

thanks in advance.

you have not shown full batch code , therefore have guess reason of variable htmlpgnr being not defined on reference.

delayedexpansion on during defining of variable , off when using it.

that sentence let me think of following used in batch file:

setlocal enabledelayedexpansion if htmlpgnr==1 set /a htmlnxtpg=2  if htmlpgnr==2 set /a htmlnxtpg=3 if htmlpgnr==3 set /a htmlnxtpg=4 if htmlpgnr==4 set /a htmlnxtpg=5 if htmlpgnr==5 set /a htmlnxtpg=6 if htmlpgnr==6 set /a htmlnxtpg=1 endlocal echo ^<body onload="timer=settimeout(function(){ window.location='file:///c:/users/myuser/dropbox/netpage/sources/page/page_%htmlnxtpg%.html';}, %htmllen%)" style="background:#408cbd"^>>>sources/page/page_%htmlpgnr%.html 

the command setlocal parameter enabledelayedexpansion not enable delayed environment variable expansion, makes copy of current environment table.

every set command modifies environment variables in new table. previous environment variable table kept in memory in meantime unmodified. changing values of existing environment variables or adding environment variables done on new table.

the command endlocal restores previous mode of delayed expansion means turning off. , additionally current environment variable table discarded , previous table restored memory.

so set operations resulting in adding, deleting or modifying variables between setlcoal , endlocal lost after command endlocal.

as variable htmlnxtpg created useless in new table enabled delayed expansion , useless option /a, variable not existing anymore after command endlocal.

as stephan suggested, 9 lines of code can replaced following 2 lines:

set /a htmlnxtpg=htmlpgnr %% 6 + 1 echo ^<body onload="timer=settimeout(function(){ window.location='file:///c:/users/myuser/dropbox/netpage/sources/page/page_%htmlnxtpg%.html';}, %htmllen%)" style="background:#408cbd"^>>>sources/page/page_%htmlpgnr%.html 

but let on setlocal , endlocal behavior on simple example:

@echo off set "test=hi!" echo  1. !test! echo  2. %test% setlocal enabledelayedexpansion echo  3. !test! echo  4. %test% set "test=hello^!" echo  5. !test! echo  6. %test% setlocal disabledelayedexpansion echo  7. !test! echo  8. %test% set "test=bonjour!" echo  9. !test! echo 10. %test% endlocal echo 11. !test! echo 12. %test% endlocal echo 13. !test! echo 14. %test% set "test=" pause 

running batch file results in output:

 1. !test!  2. hi!  3. hi!  4. hi  5. hello!  6. hello  7. !test!  8. hello!  9. !test! 10. bonjour! 11. hello! 12. hello 13. !test! 14. hi! 
  1. !test! output delayed environment variable expansion not enabled default.
  2. hi! correct output on referencing value of variable test while delayed expansion not being enabled.
  3. hi! output referencing value of variable test delayed expansion because delayed expansion enabled , variable still exists because copy of entire table made before.
  4. hi without explanation mark output on referencing value of variable test because of exclamation mark interpreted command line interpreter beginning of delayed variable reference.
  5. hello! correct output delayed expansion after modifying variable test.
    modification needs done escaping exclamation mark otherwise command line interpreter interpret ! again beginning of delayed expanded variable reference on assigning new string variable test.
  6. hello without exclamation mark output on referencing new value of test same reason before.
  7. !test! output delayed environment variable expansion disabled again.
  8. hello! correct output test after disabling delayed expansion , creating 1 more copy of entire environment variables table.
  9. !test! output delayed environment variable expansion still disabled although value of test changed once more.
  10. bonjour! correct output value of third instance of test.
  11. hello! output after endlocal discarded third table , restored delayed expansion mode.
  12. hello indicates delayed expansion again active second table because exclamation mark again not output.
  13. !test! output because after 1 more endlocal second table discarded , on initial table delayed expansion being disabled again.
  14. hi! final output on referencing value of first instance of test before deleting variable.

i hope, simple example helps understand commands setlocal , endlocal do.


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -