Article
· Nov 8, 2019 1m read

freeze & thaw scripts on windows - a 'gotcha'!

Hi, 

It turns out that on windows if you run a command with a windows command file you need to escape the % character as %%

In my case I could test freeze and thaw calls at the command line successfully as

..\bin\cache -s. -U%SYS ##Class(Backup.General).ExternalFreeze()

...but when my freeze script ran it would fail.

it turns out that a single '%' is striped when run in a windows command file, and it must be escaped as '%%' windows gets:

..\bin\cache -s. -USYS ##Class(Backup.General).ExternalFreeze()

So make sure your freeze and thaw scripts and include a double %%; 

..\bin\cache -s. -U%%SYS ##Class(Backup.General).ExternalFreeze()
 

I hope this helps

 

Stephen

 

PS In the case of the documentation it is worth noting that the thaw command wont run because it lacks the double %% :

https://cedocs.intersystems.com/latest/csp/documatic/%25CSP.Documatic.cls?PAGE=CLASS&LIBRARY=%25SYS&CLASSNAME=Backup.General#ExternalFreeze

 

'freeze.cmd' (with correct escaping)

..\bin\cache -s. -U%%SYS ##Class(Backup.General).ExternalFreeze()
rem note that we need to check errorlevel from highest to lowest here....
if errorlevel 5 goto OK
if errorlevel 3 goto FAIL
echo errorlevel returned wrong value
goto END
:OK
echo SYSTEM IS FROZEN
goto END
:FAIL
echo SYSTEM FREEZE FAILED
:END

'thaw.cmd' (this will fail because the % will get stripped. ::sad face::) 
rem Now unfreeze the system
..\bin\cache -s. -U%SYS ##Class(Backup.General).ExternalThaw()

Discussion (3)0
Log in or sign up to continue

Stephen, agree with you, those %% can be nasty, while it's possible to avoid them in this very case:

..\bin\cache -s. -U"%SYS" <Routine/ClassMethod call>

making the command syntax very similar to Linux one. In most other cases %% are inevitable; take a look at a small brief from real CMD script: 

 call :CheckNameSpace %%%%SYS
 if %sc% equ 0 goto :help
 ...
:CheckNameSpace
 set sc=1
 If "%1" == "" goto :NameSpaceNotSet
 ...