Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Standard DELAYEDEXPANSION problem.</p> <p>This is ONE compound statement:</p> <pre><code>if "%CURRENTTIME%" LSS "%BREAKUNTIL%" ( shutdown -s -t 30 ) else ( shutdown -s -t 1800 set CLOSETIME = %CURRENTTIME% echo CLOSETIME: %CLOSETIME% set /A CLOSETIME = %CLOSETIME% + 30 set /A CLOSETIME = %CLOSETIME% %% 1440 echo %CLOSETIME% echo %CLOSETIME% &gt; lastclose.txt ) </code></pre> <p>When the statement is PARSED, the CURRENT values of any <code>%var%</code> are substituted and <strong><em>THEN</em></strong> the statement is executed. The value isn't ASSIGNED to <code>closetime</code> until the statement is EXECUTED, hence the statement is interpreted as</p> <pre><code>if "%CURRENTTIME%" LSS "%BREAKUNTIL%" ( shutdown -s -t 30 ) else ( shutdown -s -t 1800 set CLOSETIME = %CURRENTTIME% echo CLOSETIME: set /A CLOSETIME = + 30 set /A CLOSETIME = %% 1440 echo echo &gt; lastclose.txt ) </code></pre> <p>Easiest cure is to change this sequence to</p> <pre><code>if "%CURRENTTIME%" LSS "%BREAKUNTIL%" ( shutdown -s -t 30 GOTO :EOF ) shutdown -s -t 1800 set CLOSETIME = %CURRENTTIME% echo CLOSETIME: %CLOSETIME% set /A CLOSETIME = %CLOSETIME% + 30 set /A CLOSETIME = %CLOSETIME% %% 1440 echo %CLOSETIME% echo %CLOSETIME% &gt; lastclose.txt </code></pre> <p>Note that <code>GOTO :EOF</code> where the colon is <code>required</code> means 'go to the physical end-of-file.</p> <p>Second easiest is to execute</p> <pre><code>SETLOCAL ENABLEDELAYEDEXPANSION </code></pre> <p>somewhere before this <code>IF</code> statement (commonly directly after the <code>@echo off</code>) and change the <code>IF</code> to</p> <pre><code>if "%CURRENTTIME%" LSS "%BREAKUNTIL%" ( shutdown -s -t 30 ) else ( shutdown -s -t 1800 set CLOSETIME = %CURRENTTIME% echo CLOSETIME: !CLOSETIME! set /A CLOSETIME = !CLOSETIME! + 30 set /A CLOSETIME = !CLOSETIME! %% 1440 echo !CLOSETIME! echo !CLOSETIME! &gt; lastclose.txt ) </code></pre> <p>Noting that when <code>DELAYEDEXPANSION</code> is in effect, <code>!var!</code> returns the RUNTIME value of <code>var</code> (ie as it changes) whereas <code>%var%</code> returns the PARSE-TIME value of <code>var</code> (ie as it stood when the statement was parsed, before execution.)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload