Page 1 of 2
Debugging / syntax checksing tools for batch
Posted: 14 May 2020 05:29
by Yanta
One of my scripts is 6,000 lines long. It has a bug. Invalid syntax or some such.
I've spent a week going over the code so many times. I've checked of unbalanced parenthesis, quotes and so on. Damned if I can find it.
So I used the batcodecheck program, but it's very basic and doesn't find any issues. I've removed the @Echo off and I've got output going to a log file.
Are there any tools or batch IDEs that will allow me to syntax check or step through the code without actually executing it?
thanks
Re: Debugging / syntax checksing tools for batch
Posted: 14 May 2020 20:59
by ShadowThief
If such a program exists, I've never heard of one.
Best you can do is standard troubleshooting:
- remove @echo off
- run the script from the command line instead of double-clicking it
- remove the parts of the script that definitely aren't causing it
- make sure you've got quotes around basically everything
- get a rubber duck, either literal or otherwise
Re: Debugging / syntax checking tools for batch
Posted: 14 May 2020 23:14
by Yanta
1-4 done. Many times.
Echo off removed.
it only runs from command line. It has to be run as administrator.
I extracted the section of code where it fails with the "syntax is invalid" and it works perfectly.
So I added in the preceding section, tried again, still ok. Added the next section in and tried again. It works fine.
Checked quotes and parenthesis. There was a mismatch of 1 between ( and ) but I fixed that.
I don't understand the rubber duck reference.
The script is edited with Notepad++ which highlights the ( ) sections when you place cursor on a line with ( or ). In some cases it gets the start and end wrong. I don't know if that's a bug in Notepad++, but the ('s and )'s are balanced. I spent 3 hours going over the code line by line matching every ( and ). And making sure there were no spaces or tabs at the end of any line of code. I even went so far as to remove any ( and ) from rem and echo statements so as not to confuse things.
Is there another IDE I can use for batch scripting? What do other people use?
Re: Debugging / syntax checksing tools for batch
Posted: 14 May 2020 23:20
by ShadowThief
https://en.wikipedia.org/wiki/Rubber_duck_debugging - show your code to either a real person or an imaginary friend and walk through the script one line at a time.
I use Notepad++ about 90% of the time, and the other 10% I use Visual Studio Code.
And of course, you can always post your code here and we can look through it to see what you missed.
Re: Debugging / syntax checksing tools for batch
Posted: 14 May 2020 23:22
by Jer
I am a batch hobbyist working on large scripts, and these tips help me in debugging.
- First, did you close the console window and rerun? If it worked without error, you could have had interfering variables in the environment.
I am assuming you do not want your batch script to leave variables assigned after the script has exited and you are using
setlocal to do this. Probably many setlocals and endlocals in your 6000-line file.
- Make a backup periodically and definitely before doing major editing. If you can't solve the issue (doing so will improve your skills),
go back to the recent backup file, and copy & paste revisions into it, testing as you go.
- When you get the syntax error in the future, obviously you want to look at lines you just changed.
- Does running the code with "exit /b", starting near the top and progressively further into the code give you a clue where the issue starts?
- Can you comment out the changed or added lines and run the script in a new console window without error?
- Can you view your running version (hopefully you have one) with the non-working version in your editor?
- Did the error start with adding or changing a function? If so, totally rem the function and the call to the
function, then do you get something other than "syntax error"? It may solve to debug or rewrite the function.
- Could it be that you are doing a comparison with an undeclared variable? That give me a syntax error.
- Before and after a run, type "set" at the command prompt. Your environmental variables should be the same before and after (I think).
Good luck.
Jerry
Re: Debugging / syntax checksing tools for batch
Posted: 15 May 2020 00:00
by jeb
Hi Yanta,
if you don't know the line where the error occurs, you could add markers like
Code: Select all
echo Line: 123 >> debug.txt
...
echo Line: 456 >> debug.txt
Add these markers until you know the exactly line number.
The rest should be easy.
It should be possible to add the markers automatically with JREPL to each line, but the ones beginning with a parenthesis
Re: Debugging / syntax checksing tools for batch
Posted: 15 May 2020 06:15
by Eureka!
This is what I do:
- run script with @echo on
- On strategic places add code similar to this:
PAUSE Start For-Loop1
The PAUSE command will ignore the "Start For-Loop1" part, but it will be shown on the screen, so you know where you are.
And more important: it limts the amount of output at a time, making zooming in a lot easier.
Let's say the problem is inside this FOR-loop:
Code: Select all
set DEBUG=echo
For ... DO (
some code
%DEBUG% var1=!var1!
more code
)
set DEBUG=REM
If all works OK, change the first line (
set DEBUG=echo) to
set DEBUG=REM
In my experience: Don't delete the DEBUG lines yet. Quite often I need to go back to debugging after reorganizing the script.
P.S. Good luck with debugging!
After a week (!!) of debugging, I would consider "Dancing around an oak tree at midnight during full moon" something worth trying ... (or did you already do that?)
P.S.2 There is also CMDebug from JPSoft. It should work as a debugger. Took a look at it about a year ago, but the program choked on the first 5 (not overly complicated) scripts I tried. Furthermore: it could not step into FOR-loops, making this close to useless for it's purpose.
So: Not recommended, just mentioning it.
P.S.3
Yanta wrote: ↑14 May 2020 05:29
step through the code without actually executing it?
That is not possible. The code has to be executed to get output. Example:
tasklist | findstr /i "notepad".
Re: Debugging / syntax checksing tools for batch
Posted: 15 May 2020 18:12
by Joe Caverly
Many improvements have been made in the CMD Debugger program available from JPSoft.
You can download a fully functional 30 Day Trial from
https://jpsoft.com/products/cmdebug-ide.html
If you have problems with debugging your DOS Batch files with the CMD Debugger, let Rex know in the
https://jpsoft.com/forums/forums/cmd.29/ forum.
Joe
Re: Debugging / syntax checksing tools for batch
Posted: 15 May 2020 23:52
by Yanta
Ouch. A$170. Well, I'll give it a go.
Just out of curiosity, can anyone spot the bug here? The first non-remark after :L510 kills the script with 'the syntax of the command is invalid'. Doesn't matter that I put there, it will always be the first non-remark after the label. I've included the preceding and succeeding sections
Code: Select all
:L500
Rem *****************************************************************************************
Rem * Firefox. *
Rem * Added handling of Chrome folder: Chrome is expected to be in profiles folder *
Rem * Updated Firefox ESR to 60.7.1 20/06/2019 *
Rem * Updated Firefox ESR to 68.5.0 14/01/2020 *
Rem * Complete re-write of firefox installation code 15/04/2019 *
Rem * Firefox=None means do not copy a profile folder. *
Rem * FFoxESR: Y= Install ESR, N=Install Latest, S=Skip Install, L=Install latest version *
Rem * 21/01/2020: Add handling of Firefox group policy templates and the policies.json file *
Rem *****************************************************************************************
Echo Installing Firefox
Echo %time% Determining Firefox version to be installed >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF /I "%FFoxESR:~0,1%"=="S" (
Echo %time% Not installing firefox >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
GOTO L510
)
IF /I "%FireFox%"=="" (
Echo %time% Not installing firefox - Profile folder not specified >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
GOTO L510
)
IF /I "%FireFox%"=="None" (
Echo %time% Not installing firefox >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
GOTO L510
)
Echo %time% Set which ini file is used where QL=Y vs QL=N >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF /I "%DoQL:~0,1%"=="Y" set FoxIni=FireFoxQL.ini
IF /I "%DoQL:~0,1%"=="N" set FoxIni=FireFoxTB.ini
Echo %time% Using ini file %SRC%\PostInstall\%FoxIni% >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
Rem Updated to 68.8.0 10/05/2020
Rem Add group policy and policies.json handling
IF /I "%FFoxESR:~0,1%"=="Y" (
Echo %time% Installing Firefox version: 68.8.0esr >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
"%SRC%\PostInstall\Firefox Setup 68.8.0esr" /INI="%SRC%\PostInstall\%FoxIni%" >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF EXIST "%SRC%\PostInstall\admx\firefox.adml" IF EXIST "%SRC%\PostInstall\admx\firefox.admx" (
copy "%SRC%\PostInstall\admx\firefox.adml" "%WINDIR%\PolicyDefinitions\en-US" /y >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
copy "%SRC%\PostInstall\admx\firefox.admx" "%WINDIR%\PolicyDefinitions" /y >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
IF EXIST "%SRC%\PostInstall\admx\mozilla.adml" IF EXIST "%SRC%\PostInstall\admx\mozilla.admx" (
copy "%SRC%\PostInstall\admx\mozilla.adml" "%WINDIR%\PolicyDefinitions\en-US" /y >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
copy "%SRC%\PostInstall\admx\mozilla.admx" "%WINDIR%\PolicyDefinitions" /y >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
IF EXIST "%SRC%\PostInstall\distribution\" (
md "%PROGRAMFILES%\Mozilla Firefox\distribution"
copy "%SRC%\PostInstall\distribution\policies.json" "%PROGRAMFILES%\Mozilla Firefox\distribution" /y >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
Rem Save version number in registry for later use
REG ADD "HKEY_CURRENT_USER\Software\Mozilla\Firefox" /v Version /d "68.8.0esr" /t REG_SZ /f >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
IF /I "%FFoxESR:~0,1%"=="L" (
Echo %time% Installing Firefox version: 76.0.1 >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
"%SRC%\PostInstall\Firefox Setup 76.0.1" /INI="%SRC%\PostInstall\%FoxIni%" >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
Rem https://getadmx.com/HKLM/Software/Policies/Mozilla/Firefox
Echo %time% Disabling Firefox Telemetry and Auto Updates >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
REG ADD "HKEY_LOCAL_MACHINE\Software\Policies\Mozilla\Firefox" /v DisableTelemetry /d 1 /t REG_DWORD /f >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
REG ADD "HKEY_LOCAL_MACHINE\Software\Policies\Mozilla\Firefox" /v DisableAppUpdate /d 1 /t REG_DWORD /f >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
REG ADD "HKEY_LOCAL_MACHINE\Software\Policies\Mozilla\Firefox" /v DisableDeveloperTools /d 1 /t REG_DWORD /f >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
REG ADD "HKEY_LOCAL_MACHINE\Software\Policies\Mozilla\Firefox" /v DisableFeedbackCommands /d 1 /t REG_DWORD /f >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
REG ADD "HKEY_LOCAL_MACHINE\Software\Policies\Mozilla\Firefox" /v DisableFirefoxStudies /d 1 /t REG_DWORD /f >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
Rem More telemetry from v75 of Firefox https://www.bleepingcomputer.com/news/software/firefox-now-tells-mozilla-what-your-default-browser-is-every-day/#cid15387
REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Mozilla\Firefox" /v DisableDefaultBrowserAgent /d 1 /t REG_DWORD /f >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
Rem Save version number in registry for later use
REG ADD "HKEY_CURRENT_USER\Software\Mozilla\Firefox" /v Version /d "76.0.1" /t REG_SZ /f >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
IF /I NOT "%FIREFOX%"=="" (
Echo %time% Importing Firefox profile.ini >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF NOT EXIST "%APPDATA%\Mozilla" MD "%APPDATA%\Mozilla" >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF NOT EXIST "%APPDATA%\Mozilla\FireFox" MD "%APPDATA%\Mozilla\FireFox" >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
copy "%SRC%\PostInstall\%USERNAME%\profiles.ini" "%APPDATA%\Mozilla\FireFox" /y >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF EXIST "%SRC%\PostInstall\%USERNAME%\Profiles\" IF NOT EXIST "%FireFox%\" (
Echo %time% Copying Profile Data to %Firefox% >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
xcopy "%SRC%\PostInstall\%USERNAME%\Profiles" "%FireFox%" /e/q/y/c/k/i/h/x >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
IF NOT EXIST "%SRC%\PostInstall\%USERNAME%\Profiles\" IF NOT EXIST "%FireFox%\" (
Echo %time% Firefox Profiles folder %FireFox% could not be created. Firefox will create a folder when it starts >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
Echo %time% Check that the profile name referenced in Profiles.ini matches the folder at %FireFox% >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
Rem Get the profile folder exact name and if found, copy the prefs.js file to it.
IF EXIST "%SRC%\PostInstall\prefs.js" (
for /F "Tokens=2 delims==" %%a in ('findstr /I "path" %APPDATA%\Mozilla\Firefox\profiles.ini') do set "ProfileFolder=%%a"
IF NOT "%ProfileFolder%"=="" (
Echo %time% Firefox profile folder is %ProfileFolder% >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
copy "%SRC%\PostInstall\prefs.js" "%ProfileFolder%" /y >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
)
Echo %time% Cleaning up Firefox shortcuts >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF EXIST "%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs\Firefox.Lnk" (
copy "%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs\Firefox.Lnk" "%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs\Internet" /y >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
IF NOT EXIST "%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs\Internet\Firefox.Lnk" IF EXIST "%APPDATA%\Microsoft\Windows\Start Menu\Programs\FireFox.Lnk" (
copy "%APPDATA%\Microsoft\Windows\Start Menu\Programs\Firefox.Lnk" "%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs\Internet" /y >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
IF NOT EXIST "%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs\Internet\Firefox.Lnk" IF EXIST "%SRC%\PostIntall\%USERNAME%\Quick Launch\Forefox.lnk" (
copy "%SRC%\PostIntall\%USERNAME%\Quick Launch\Forefox.lnk" "%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs\Internet" /y >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF NOT EXIST "%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs\Internet\Firefox.Lnk" Echo %time% Cannot find Firefox shortcut >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
IF EXIST "%APPDATA%\Microsoft\Windows\Start Menu\Programs\FireFox.Lnk" del "%APPDATA%\Microsoft\Windows\Start Menu\Programs\Firefox.Lnk" >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF EXIST "%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs\Firefox.Lnk" del "%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs\Firefox.Lnk" >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
:L510
Rem *********************************************************************************************************************************************
Rem * Windows 7 games for Windows 10 and other games *
Rem *********************************************************************************************************************************************
IF /I NOT "%DoGame:~0,1%"=="Y" Echo %time% Not installing games >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF /I "%DoGame:~0,1%"=="Y" (
Echo Installing/Configuring Games
Echo %time% Installing games and settings >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF /I NOT "%USERNAME%"=="Peyton" IF /I NOT "%USERNAME%"=="Corey" IF /I NOT "%USERNAME%"=="Corey-Kodi" (
IF EXIST "%SRC%\PostInstall\W7GW10.exe" (
Echo %time% Installing Windows 7 Games for Windows 10 >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
Start "Windows 7 Games" /d "%SRC%\PostInstall\" "W7GW10.exe"
)
)
IF EXIST "%PROGRAMFILES%\Microsoft Games\" (
REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Applications\freecell.exe" /v NoStartPage /d 1 /t REG_DWORD /f >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Applications\solitaire.exe" /v NoStartPage /d 1 /t REG_DWORD /f >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Applications\mahjong.exe" /v NoStartPage /d 1 /t REG_DWORD /f >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Applications\Hearts.exe" /v NoStartPage /d 1 /t REG_DWORD /f >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Applications\spidersolitaire.exe" /v NoStartPage /d 1 /t REG_DWORD /f >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
Rem BOS high scores
IF EXIST "%RegPath%\bos.reg" (
Echo %time% Balls of Steel >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
REG IMPORT "%RegPath%\bos.reg" >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
Rem Hoyle Card games (2004)
IF EXIST "%SRC%\PostInstall\%USERNAME%\Hoyle\" (
Echo %time% Hoyle card games >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
xcopy "%SRC%\PostInstall\%USERNAME%\Hoyle\*.*" "%APPDATA%\Hoyle" /e/q/y/c/k/i/h >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
Rem PopCap games
IF EXIST "%SRC%\PostInstall\%USERNAME%\PopCap Games\" (
Echo %time% PopCap games >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
xcopy "%SRC%\PostInstall\%USERNAME%\PopCap Games" "%PROGRAMDATA%\PopCap Games" /e/q/y/c/k/i/h/x >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF EXIST "%RegPath%\Popcap.reg" (
REG IMPORT "%RegPath%\Popcap.reg" >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
)
IF EXIST "%SRC%\PostInstall\%USERNAME%\LA PopCap Games\" (
Echo %time% LocalAPPData PopCap games >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
xcopy "%SRC%\PostInstall\%USERNAME%\LA PopCap Games" "%LOCALAPPDATA%\PopCap Games" /e/q/y/c/k/i/h/x >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
Rem Misc games
IF EXIST "%SRC%\PostInstall\%USERNAME%\Saved Games\" (
xcopy "%SRC%\PostInstall\%USERNAME%\Saved Games" "%USERPROFILE%\Saved Games" /e/q/y/c/k/i/h/x >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
Rem Microsoft Games folder (Some games go in local Eg W7G4W10, some go in roaming Eg Rise of nations)
IF EXIST "%SRC%\PostInstall\%USERNAME%\AD Microsoft Games\" (
xcopy "%SRC%\PostInstall\%USERNAME%\AD Microsoft Games" "%APPDATA%\Microsoft Games" /e/q/y/c/k/i/h/x >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
IF EXIST "%SRC%\PostInstall\%USERNAME%\Microsoft Games\" (
xcopy "%SRC%\PostInstall\%USERNAME%\Microsoft Games" "%LOCALAPPDATA%\Microsoft Games" /e/q/y/c/k/i/h/x >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
:L520
Rem Runescape
IF EXIST "%SRC%\PostInstall\%USERNAME%\RuneScape-Setup.exe" (
Echo Installing RuneScape
Echo %time% RuneScape >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
"%SRC%\PostInstall\%USERNAME%\RuneScape-Setup" /s
)
IF EXIST "%SRC%\PostInstall\%USERNAME%\Alt1Setup.exe" (
Echo Installing ALT1 Toolkit
Echo %time% Installing Alt1 Toolkit >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
"%SRC%\PostInstall\%USERNAME%\Alt1Setup" /s
IF EXIST "%SRC%\PostInstall\%USERNAME%\Alt1Toolkit\" (
Echo %time% Copying ALT1 local files >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
xcopy "%SRC%\PostInstall\%USERNAME%\Alt1Toolkit" "%LOCALAPPDATA%\Alt1Toolkit" /e/q/y/c/k/i/h/x >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
)
Rem Runescape cache files
IF EXIST "%SRC%\PostInstall\%USERNAME%\JagexCache\" (
Echo %time% Copying Runescape Cache folder >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
xcopy "%SRC%\PostInstall\%USERNAME%\JagexCache" "%USERPROFILE%\JagexCache" /e/q/y/c/k/i/h >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF EXIST "%SRC%\PostInstall\%USERNAME%\Jagex\" (
xcopy "%SRC%\PostInstall\%USERNAME%\Jagex" "%LOCALAPPDATA%\Jagex" /e/q/y/c/k/i/h >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
IF EXIST "%RegPath%\jagex.reg" (
REG IMPORT "%RegPath%\jagex.reg" >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
IF EXIST "%RegPath%\runscape.reg" (
REG IMPORT "%RegPath%\runescape.reg" >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
IF EXIST "%SRC%\PostInstall\%USERNAME%\jagex_cl_runescape_LIVE.dat" (
copy "%SRC%\PostInstall\%USERNAME%\jagex_cl_runescape_LIVE.dat" "%USERPROFILE%" >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
IF EXIST "%SRC%\PostInstall\%USERNAME%\jagexappletviewer.preferences" (
copy "%SRC%\PostInstall\%USERNAME%\jagexappletviewer.preferences" "%USERPROFILE%" >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
)
:L530
Rem SLADE3 is a modern editor for Doom-engine based games and source ports. Requires MS VC 2015 x86.
Rem Looks like Corey saves his work in a downloads folder? F:\Downloads\GZ Doom Work\WAD Edits?
IF EXIST "%SRC%\PostInstall\%USERNAME%\Setup_SLADE_3.1.5.exe" (
Echo Installing Slade 3
Echo Installing Slade 3 >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
"%SRC%\PostInstall\%USERNAME%\Setup_SLADE_3.1.5.exe" /s >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF EXIST "%SRC%\PostInstall\%USERNAME%\Slade3\" (
xcopy "%SRC%\PostInstall\%USERNAME%\slade3" "%APPDATA%\Slade3" /e/q/y/c/k/i/h/x >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
)
Rem GZDoom and GZDoom Builder: Needs an ini file for settings & location of WAD files. These are portable programs
IF EXIST "%SRC%\PostInstall\%USERNAME%\gzdoom.rar" (
Echo GZ Doom components
Echo %time% GZ Doom components >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
unrar x -y -iddp "%SRC%\PostInstall\%USERNAME%\gzdoom.rar" *.* "%PROGRAMFILES%" >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF EXIST "%SRC%\PostInstall\%USERNAME%\GZDOOM-%USERNAME%.ini" copy "%SRC%\PostInstall\%USERNAME%\GZDOOM-%USERNAME%.ini" "%PROGRAMFILES%\GZDoom" /y >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF EXIST "%SRC%\PostInstall\%USERNAME%\GZDoom.lnk" copy "%SRC%\PostInstall\%USERNAME%\GZDOOM.lnk" "%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs\Games" /y >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF /I "%Menu:~0,1%"=="N" (
IF /I "%DoQL:~0,1%"=="Y" copy "%SRC%\PostInstall\%USERNAME%\GZDoom.lnk" "%APPDATA%\Microsoft\Internet Explorer\Quick Launch" /y >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF /I "%DoQL:~0,1%"=="N" copy "%SRC%\PostInstall\%USERNAME%\GZDoom.lnk" "%APPDATA%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar" /y >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
)
IF EXIST "%SRC%\PostInstall\%USERNAME%\GZ Doom Builder.rar" (
unrar x -y -iddp "%SRC%\PostInstall\%USERNAME%\GZ Doom Builder.rar" *.* "%PROGRAMFILES%" >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF EXIST "%SRC%\PostInstall\%USERNAME%\GZDoom Builder.lnk" copy "%SRC%\PostInstall\%USERNAME%\GZDOOM Builder.lnk" "%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs\Games" /y >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF /I "%Menu:~0,1%"=="N" (
IF /I "%DoQL:~0,1%"=="Y" copy "%SRC%\PostInstall\%USERNAME%\GZDoom Builder.lnk" "%APPDATA%\Microsoft\Internet Explorer\Quick Launch" /y >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF /I "%DoQL:~0,1%"=="N" copy "%SRC%\PostInstall\%USERNAME%\GZDoom Builder.lnk" "%APPDATA%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar" /y >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
)
Rem PS3 Joystick Controller software
IF EXIST "%SRC%\PostInstall\%USERNAME%\SCP\" (
Echo %time% Copying PS3 controller software >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
xcopy "%SRC%\PostInstall\%USERNAME%\SCP" "%PROGRAMFILES%\SCP" /e/q/y/c/k/i/h/x >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
:L535
Rem *********************************************************************************************************************************************
Rem * BATTLE.NET *
Rem * *
Rem * Offline install not possible so have to copy files the old way *
Rem * Note: The SteamDrive variable is used for location of all games *
Rem * %PROGRAMDATA% Blizzard Entertainment folder is a cache folder. Does not need to be copied here. *
Rem * %LOCALAPPDATA% Blizzard Entertainment folder is a telemetry folder. Does not need to be copied here. *
Rem * Starting DeckTracker at start up creates a run entry that runs a program call update.exe, publisher GitHub *
Rem *********************************************************************************************************************************************
IF /I "%DoHS:~0,1%"=="N" GOTO L540
IF EXIST "%SRC%\PostInstall\%USERNAME%\Battle.net\" (
Echo %time% Copying Battle.Net files to %SteamDrive% >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
xcopy "%SRC%\PostInstall\%USERNAME%\Battle.Net" "%SteamDrive%\PROGRAM FILES (x86)\Battle.Net" /e/q/y/c/k/i/h/x >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF NOT EXIST "%SRC%\PostInstall\%USERNAME%\PDBattleNet\" Echo %time% Battle.Net programdata folder missing >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF NOT EXIST "%SRC%\PostInstall\%USERNAME%\LABattleNet\" Echo %time% Battle.Net Local Appdata folder missing >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF NOT EXIST "%SRC%\PostInstall\%USERNAME%\RABattleNet\" Echo %time% Battle.Net Appdata folder missing >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF NOT EXIST "%RegPath%\blizzard.reg" Echo %time% Battle.Net registry settings missing >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF NOT EXIST "%SteamDrive%\PROGRAM FILES (x86)\Battle.net\Battle.net Launcher.exe" Echo %time% Battle.Net launcher missing. Previous copy may have failed >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF EXIST "%SteamDrive%\PROGRAM FILES (x86)\Battle.net\Battle.net Launcher.exe" (
IF EXIST "%SRC%\PostInstall\%USERNAME%\PDBattleNet\" (
xcopy "%SRC%\PostInstall\%USERNAME%\PDBattleNet" "%PROGRAMDATA%\Battle.Net" /e/q/y/c/k/i/h/x >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
IF EXIST "%SRC%\PostInstall\%USERNAME%\LABattleNet\" (
xcopy "%SRC%\PostInstall\%USERNAME%\LABattleNet" "%LOCALAPPDATA%\Battle.Net" /e/q/y/c/k/i/h/x >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
IF EXIST "%SRC%\PostInstall\%USERNAME%\LABlizzard\" (
xcopy "%SRC%\PostInstall\%USERNAME%\LABlizzard" "%LOCALAPPDATA%\Blizzard" /e/q/y/c/k/i/h/x >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
IF EXIST "%SRC%\PostInstall\%USERNAME%\RABattleNet\" (
xcopy "%SRC%\PostInstall\%USERNAME%\RABattleNet" "%APPDATA%\Battle.Net" /e/q/y/c/k/i/h/x >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
IF EXIST "%RegPath%\blizzard.reg" (
REG IMPORT "%RegPath%\Blizzard.reg" >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
Rem Quick Launch short cut
IF /I "%DoQL:~0,1%"=="Y" IF NOT EXIST "%APPDATA%\Microsoft\Internet Explorer\Quick Launch\Battle.net.lnk" (
IF EXIST "%SRC%\PostInstall\Applications\Battle.Net.Lnk" copy "%SRC%\PostInstall\Applications\Battle.Net.Lnk" "%APPDATA%\Microsoft\Internet Explorer\Quick Launch\Battle.net.lnk" /y >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
IF /I "%DoQL:~0,1%"=="N" IF NOT EXIST "%APPDATA%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Battle.net.lnk" (
IF EXIST "%SRC%\PostInstall\Applications\Battle.Net.Lnk" copy "%SRC%\PostInstall\Applications\Battle.Net.Lnk" "%APPDATA%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Battle.net.lnk" /y >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
Rem Delete all the log files
Echo %time% Removing all Battle.net log files
IF EXIST "%LOCALAPPDATA%\Blizzard\Hearthstone\Logs\" del "%LOCALAPPDATA%\Blizzard\Hearthstone\Logs\*.log" /s/q/f >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF EXIST "%LOCALAPPDATA%\Battle.net\Logs\" del "%LOCALAPPDATA%\Battle.net\Logs\*.log" /s/q/f >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF EXIST "%PROGRAMDATA%\Battle.net\Agent\Logs" del "%PROGRAMDATA%\Battle.net\Agent\Logs\*.log" /s/q/f >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
Rem Hearthstone Deck Tracker. Use the folders in %APPDATA% since this is installed like malware.
IF EXIST "%SRC%\PostInstall\%USERNAME%\RAHSDT\" (
Echo %time% Copying Hearthstone Deck Tracker files >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
xcopy "%SRC%\PostInstall\%USERNAME%\RAHSDT" "%APPDATA%\HearthstoneDeckTracker" /e/q/y/c/k/i/h/x >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
IF EXIST "%SRC%\PostInstall\%USERNAME%\LAHSDT\" (
xcopy "%SRC%\PostInstall\%USERNAME%\LAHSDT" "%LOCALAPPDATA%\HearthstoneDeckTracker" /e/q/y/c/k/i/h/x >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
IF EXIST "%RegPath%\HSDT.reg" (
Echo %time% Importing Hearthstone Deck Tracker auto run entry >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
REG IMPORT "%RegPath%\HSDT.reg" >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF "%USERNAME%"=="Phillip" (
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run" /v "Hearthstone Deck Tracker" /d "C:\Users\Phillip\AppData\Local\HearthstoneDeckTracker\Update.exe" --processStart "HearthstoneDeckTracker.exe" /t REG_SZ /f >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
)
)
)
Re: Debugging / syntax checksing tools for batch
Posted: 16 May 2020 06:05
by ShadowThief
Based solely on that snippet, it's failing because DoGame isn't set.
Re: Debugging / syntax checksing tools for batch
Posted: 16 May 2020 06:10
by Eureka!
Yanta wrote: ↑15 May 2020 23:52
Doesn't matter that I put there, it will always be the first non-remark after the label.
So, if you replace this line:
Code: Select all
IF /I NOT "%DoGame:~0,1%"=="Y" Echo %time% Not installing games >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
with:
Your script fails?
Re: Debugging / syntax checksing tools for batch
Posted: 16 May 2020 06:53
by ShadowThief
I wrote a script to echo a number after each line in your script. After getting to
it wouldn't progress past that. Since I know that code in parentheses gets parsed as a single block, I removed the if statement entirely. The script then continued on until it reached the GZDoom installer section. Again, I removed the offending if statements, and then it continued until it reached the line
. At that point, I tried setting the %Menu% and %DoQL% variables, and the script completed successfully.
Also, it didn't break anything here, but you will almost certainly run into issues by having labels inside of an if block like you have here.
Re: Debugging / syntax checksing tools for batch
Posted: 16 May 2020 08:14
by jfl
Yet another method for debugging large scripts, that I use a lot, both at home and at work, to debug very large batch files:
Use the debugging routines and macros in my
Library.bat batch library.
This works by instrumenting the problematic code, with macros defined in Library.bat.
These macros do nothing in normal executions, and they display debug information in debug mode. (Instrumented functions entry/exit; Debug messages you added; The value of variables you watch; ...)
The debug output is indented by call depth, which makes it easy to review what's going on.
You can include Library.bat features in your script by adding this line in your script initialization, before you process command-line arguments:
Then have a command-line option that enables debugging by doing (%LCALL% :Debug.On). For example:
Code: Select all
if "%~1"=="-d" %LCALL% :Debug.On & goto :next_arg
Finally instrument the functions you want to trace with %FUNCTION% / %RETURN% macros, and %ECHO.D% debug messages.
You'll find a general documentation about this
there. Scroll about 60% down the file, to the "The Batch library" section.
There's also an example of what the debug output looks like.
For a complete list of debug macros, see the Library.bat header.
Re: Debugging / syntax checksing tools for batch
Posted: 16 May 2020 08:24
by penpen
Just in case the reason is unclear, it is explained in detail here:
viewtopic.php?f=3&t=3130&p=60873#p60873
One of multiple possible workarounds could be, that if an environment variable is undefined, then set it to a default value, before you use a substring, for example:
Code: Select all
if not defined DoGame set "DoGame=No"
if /I "%DoGame:~0,1%"=="Y" (
:: ...
penpen
Re: Debugging / syntax checksing tools for batch
Posted: 16 May 2020 19:27
by Yanta
ShadowThief wrote: ↑16 May 2020 06:05
Based solely on that snippet, it's failing because DoGame isn't set.
My bad. I should have stated "You can assume all variables have been set". The code that does that is at the top of the script
Code: Select all
IF /I "%USERNAME%"=="Phillip" (
set DataDrv=F:
set LogPath=F:\Logs
set TempPath=G:\Temp2
set UserPath=F:\Users\%USERNAME%
set FireFox=F:\Users\%USERNAME%\Profiles
set FFoxESR=Y
set DoApps=Y
set DoSteam=N
set DoKodi=R
set DoGame=Y
set DoCool=Y
set OpenVPN=A
set Word=XXXXXXXX
set Menu=Y
set DoQL=Y
set DoGPO=Y
set pFile=G:
set Server=Server
set VPNServ=auXXX.nordvpn.com.udp.ovpn
set WinAero=H:\WinAeroTweaker
set SvcHost=0x020A9984
Set VMDrive=
set DoTenG=Y
set SteamDrive=D:
set KeyPC=Y
set DoHS=N
set Macrium=Y
set Reflect=XX-XXXX-XXXX-XXXX
)
[\code]
But even if that were true the the entire code section should not be executed. Syntactically the command is correct and should evaluate (if DoGame were not set), to.. IF /I NOT ""=="Y" ...
In this case, DoGame is set as you can see from the code above so the test is IF /I NOT "Y"=="Y" ... so it evaluate to false.
That should not fail with a syntax error and crash the script.
But even if I replace that line with Echo Hello World, that will fail with a syntax error. If I put in set x=y it fails with syntax error. If I put copy a b it will fail with a syntax error. Always at that exact place.