Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Help with CMDebug 36.49 Restructuring from CMD to TCC

Jan
179
2
Last time when I trial CMDebug there were issues regarding CMD if's vs TCC. If I rewrite these if's to work with the debugger will they work outside the debugger? Also will it fix the quirky step through in the debugger?
 
There is a bug in the CMD IF processing; TCC by default duplicates this bug (and a couple of other minor ones), though this can be disabled if you prefer the TCC approach.

Are you wanting to create CMD-only batch files or TCC batch files?

I don't know what you mean by the "quirky step through" - can you elaborate?
 
Let's start here. I wasn't wanting to redo to go to TCC I was just thinking some of the issues in CMDebug were inconsistancies between the two. I cannot get a simple string compare to work.

Batch Parameters
2=Start (shows just like this in the Batch Parameters with no extra spaces on either end)

CMDebug
If %2 == [Start] (
Goto Parm1OK)
(blank line #1)
(blank line #2)
Next statement

It's that simple but I've tried it using spaces around the == I've tried it using the mnemonics I've tried it without the parens I've tried it wiht brackets on both sides and without brackets I've tried negating it and using else...this shouldn't be this hard. It worked under CMD in fact I never had an issue with it but now I cannot get it to goto.

The original script before I started with CMDebug was this which I think having the : on the goto line is technically wrong.
If [%1]==[Start] goto :Parm1OK

Using the same "if" the debuger highlights the first line, the 2nd will never highlight for the reasons I listed above and then the current line becomes the line after the if...the whitespace line inbetween this statement and the next which I actually have 2 lines so it hghtlights each one in succession.

Here's another that just won't work...

Batch Parameters
2=0

CMDebug
Iff @NUMERIC[%2] Then (
Set LPassed=0
) Else (
Set LPassed=1
Endiff )

The highlighting on this one goes immediately to the last line the Endiff ) then when I think it will hit the next statement out of the blue it returns to the calling script. I must have changed something because it was highligting the first line then going to the else logic. In the help file the table in there shows that there's supposed to be a % in front of the @. I tired it with and without, neither worked. Again I tried all types of changes and got no where. With the parens without them without the then and even a regular if contruct. At some point I got the idea that there was no "if" in TCC that instead it was using Iff to replace the CMD if structure.

Is there a way to stop having to change the Read-only setting everytime I guess you reload or restart every script? Is there a way to change the default setting?

One more. Is there a way to identify the executing script line number?

I'm not getting email notifications for some reason.
 
Let's start here. I wasn't wanting to redo to go to TCC I was just thinking some of the issues in CMDebug were inconsistancies between the two. I cannot get a simple string compare to work.

Batch Parameters
2=Start (shows just like this in the Batch Parameters with no extra spaces on either end)

CMDebug
If %2 == [Start] (
Goto Parm1OK)
(blank line #1)
(blank line #2)
Next statement

It's that simple but I've tried it using spaces around the == I've tried it using the mnemonics I've tried it without the parens I've tried it wiht brackets on both sides and without brackets I've tried negating it and using else...this shouldn't be this hard. It worked under CMD in fact I never had an issue with it but now I cannot get it to goto.

The original script before I started with CMDebug was this which I think having the : on the goto line is technically wrong.
If [%1]==[Start] goto :Parm1OK

Using the same "if" the debuger highlights the first line, the 2nd will never highlight for the reasons I listed above and then the current line becomes the line after the if...the whitespace line inbetween this statement and the next which I actually have 2 lines so it hghtlights each one in succession.

Here's another that just won't work...

Batch Parameters
2=0

CMDebug
Iff @NUMERIC[%2] Then (
Set LPassed=0
) Else (
Set LPassed=1
Endiff )

The highlighting on this one goes immediately to the last line the Endiff ) then when I think it will hit the next statement out of the blue it returns to the calling script. I must have changed something because it was highligting the first line then going to the else logic. In the help file the table in there shows that there's supposed to be a % in front of the @. I tired it with and without, neither worked. Again I tried all types of changes and got no where. With the parens without them without the then and even a regular if contruct. At some point I got the idea that there was no "if" in TCC that instead it was using Iff to replace the CMD if structure.

Is there a way to stop having to change the Read-only setting everytime I guess you reload or restart every script? Is there a way to change the default setting?

One more. Is there a way to identify the executing script line number?

I'm not getting email notifications for some reason.

The normal way to test for comparisons (unless you're sure you don't have any spaces in the batch variables is to enclose the values to be compared in double quotes:

If "%2" == "Start"

The brackets are somewhat problematic because they are also wildcard specifiers, and they won't work if you have whitespace in the arguments.

Your GOTO argument should not have the leading ':'. The : is only used on the actual label line; i.e.:

Code:
goto Foo
echo blah blah
:Foo
echo We won't have seen blah blah

When you are single stepping through a batch file, an IF statement is collapsed into a single line. So you cannot step through individual pieces of it -- this is how CMD works and TCC must duplicate this behavior. If you want to step through individual lines in a conditional statement (and you don't need CMD compatibility) you can use the TCC commands IFF or SWITCH.

Code:
Iff @NUMERIC[%2] Then (
    Set LPassed=0
) Else (
    Set LPassed=1
Endiff )

You are missing a % in front of the @NUMERIC, and when you put a ( at the end of the line the parser is interpreting it as the beginning of a command group. It should look like this:

Code:
Iff %@NUMERIC[%2] Then
    Set LPassed=0
Else
    Set LPassed=1
Endiff

Not sure what you mean about the read-only setting. The debugger sets the batch file to read-only while it is executing because modifying a script while it is running is usually not intended (or a good idea). And if it's a .BTM file, it will have been loaded in memory before execution, and modifying the contents in the editor will not affect will the execution.

The status bar at the bottom of the debugger window will display the current line & column. There are also internal variables for the current batch file name and row, which you could monitor in the Watch window.

You have to tell Xenforo (the forum software) that you want email notifications. You can subscribe to a single thread or to all threads in a forum topic.
 
If %1==[Start] was setup because it's user entered and spaces is a real possibility. What I missed was putting the [] around the %1 which is very strange to me because it's a variable. I've never seen that in any other programming. Your right of course typically a string would be enclosed in "".

The brackets came from Microsoft's documentation on the use of IF not that they get their own product right. I was just reading a few minutes ago there are differences on how unassigned parameters are handled between CMD.exe and command.com. I wouldn't have even thought to consider something like that.

After I fixed that I notice that the script loading in the debugger does not match the script I keyed.

1779761382474.webp


What do you make of that? And it also does it on the next if statement and then reports it as an unknown command and shows a ascii heart and the If. It's also adding a tab before the goto rather than my single space.

As for the colon on the goto label I think that came from the CMDebug documentation or help file specifically where I don't recall but I'll keep my eye's open for it. I was just trying to get it to work and all the crazy permutations.

Should the debugger actually goto labels because it seems to skip over them.

Often with if's I see two behaviors in the debugger. One where it goes to the last ) if there is one and another where it steps through each line of the if so that you have no idea what logic it's following. It seems to be OK on linear if's not that there's really anything to get wonrg. Does it make any difference if you have enabled delayed expansion as to how it steps through them?

So debug doesn't handle single-conmand command groups or is that TCC? As far as I know that is legitimate in CMD.

I haven't gotten to the %@numeric yet.

Sometimes when I move execution to a prior line I feel like it's ignoring the change I made or the rexecution. I"m not sure at this point from what you're saying it should ignore the changes or that it's a bad idea? Most debuggers I've used in the past have allowed you to make changes to values and code on the fly. I assumed that's why when I would attempt to exit it was asking me to save it because I had changed it. Regardless even to change a variable value I have to go to edit and down to the bottom and turn off read-only every time a script loads regardless if it's a script that had been loaded before or not. You can imagine on a subscript that's gettting called multiple times that can be a real pita. There is a shortcut but I"m not a fan of shortcuts having to grab the keyboard unless I'm typing code is something I prefer not to do. There are 4 I use cut, copy an paste and rarely undo.

It seems like I'm not getting notifications from you at this point. I did get one from another user.

I was not able to identify a variable that contains the source line number.
 
Last edited:
What's wrong with my /F" "?

Echo "Create new log file." | Tee /F"%F, %T" /D /T "P:\Backup\BackupLogs\%2Drive%3BackupT.log"

You really should have examples of these commands in the help and not just the syntax which can be daunting.

This is the syntax as shown in help:


TEE [/= /A /Dn .E"regex" /F"format" /R /T /Unicode=[UTF-16LE | UTF-8 | ASCII[,UTF-16LE | UTF-8 | ASCII]]] file...

What is the /Dn The /D option is to display the date in yyyy-mm-dd format what is the "n" following it? Typo? Th eonly thing I get is the comman between the %F, %T followed by my "Create New Log File".
 
Last edited:
What's wrong with my /F" "?

Echo "Create new log file." | Tee /F"%F, %T" /D /T "P:\Backup\BackupLogs\%2Drive%3BackupT.log"

If you're running that from the command line, you need two %'s for the %F and the %T, as otherwise it will be expanded by the parser before TEE is executed. If the line is executed in a batch file, you only need the single %'s.

This is not specific to TEE, and CMD will behave the same way when running things at the prompt versus in a batch file.

Code:
Echo "Create new log file." | Tee /F"%%F, %%T" /D /T "P:\Backup\BackupLogs\%2Drive%3BackupT.log"

What is the /Dn The /D option is to display the date in yyyy-mm-dd format what is the "n" following it? Typo? Th eonly thing I get is the comman between the %F, %T followed by my "Create New Log File".

The 'n' is a typo in the help. /D doesn't take any arguments.
 
After I fixed that I notice that the script loading in the debugger does not match the script I keyed.

View attachment 5830

What do you make of that? And it also does it on the next if statement and then reports it as an unknown command and shows a ascii heart and the If. It's also adding a tab before the goto rather than my single space.

Please post your script and the arguments you are passing to it. It's impossible to try to reproduce your issue with a fragment of the batch file and no idea what arguments are being passed.

Should the debugger actually goto labels because it seems to skip over them.

A label isn't a command so there's no reason for the debugger to stay on a label and try to do anything. If you do a GOTO the debugger will look for the label and then continue debugging on the following line.

Often with if's I see two behaviors in the debugger. One where it goes to the last ) if there is one and another where it steps through each line of the if so that you have no idea what logic it's following. It seems to be OK on linear if's not that there's really anything to get wonrg. Does it make any difference if you have enabled delayed expansion as to how it steps through them?

Delayed expansion does not affect IF parsing. But as I said before, an IF is considered to be a single-line statement, regardless of whether you split it into multiple lines with line continuation characters or command grouping. This is how both TCC and CMD handle an IF.

If you want to step into individual commands in a conditional statement, you need to use IFF or SWITCH.

So debug doesn't handle single-conmand command groups or is that TCC? As far as I know that is legitimate in CMD.

The debugger has no problems with command groups. But if you enter a command group on a single line (or inside an IF) the debugger will not step into individual statements on that single line.

You apparently want to step inside compound commands (like a command group) that are on a single line - that is not possible with BDEBUGGER.

Sometimes when I move execution to a prior line I feel like it's ignoring the change I made or the rexecution. I"m not sure at this point from what you're saying it should ignore the changes or that it's a bad idea? Most debuggers I've used in the past have allowed you to make changes to values and code on the fly. I assumed that's why when I would attempt to exit it was asking me to save it because I had changed it. Regardless even to change a variable value I have to go to edit and down to the bottom and turn off read-only every time a script loads regardless if it's a script that had been loaded before or not. You can imagine on a subscript that's gettting called multiple times that can be a real pita. There is a shortcut but I"m not a fan of shortcuts having to grab the keyboard unless I'm typing code is something I prefer not to do. There are 4 I use cut, copy an paste and rarely undo.

If you are running a .BTM file, you cannot alter it on the fly. .BTM files are loaded into memory when they start, and there is no provision to alter them during execution.

You can change variables whenever you want.

I was not able to identify a variable that contains the source line number.

%_batchline
 
Echo "Create new log file." | Tee /F"%F, %T" /D /T "P:\Backup\BackupLogs\%2Drive%3BackupT.log"

So my Tee cmd is technically correct for batch? Because as I said earlier all I get is the comma.

Some of what I wrote above is just knowing when the debugger will move to a statement and when it won't. I have to have an expecatation to know when something has gone wrong because the current execution line is landing in strange places at times like blank lines. I don't want to assume it's doing what it should.

The parameters are: Start HPEnvy E 21 0

Be advised that I had made some changes to the attached that I haven't been able to run through the debugger because I updated CMDebug and it wouldn't load again. I'm not sure if you will get the same problem as above or not.
 

Attachments

Anything on this? You don't even need to execute the DriveBackup.cmd just load it.

I take it For Do's have the same problem with command groups as If's in they won't execute the lines in the group?

Is there a way to add a horizontal line to the toolbar?

Is there a way to display a variable value somewhere other than under my cursor when I hover? I have to wait for the hover to remove my cursor to be able to see the value.
 
I added some more validation and multiple [US] on single If now.


If [%3] == [C] goto Parm3OK
If [%3] == [D] goto Parm3OK
If [%3] == [E] goto Parm3OK
If [%3] == [M] goto Parm3OK
If [%3] == [N] goto Parm3OK
If [%3] == goto Parm3OK The copy and paste even dropped the from this line and it's getting crossed out for some reason?
If [%3] == [T] goto Parm3OK
If [%3] == goto Parm3OK
If [%3] == [V] goto Parm3OK
If [%3] == [W] goto Parm3OK
If [%3] == [Y] goto Parm3OK

Interesting. It doesn't copy over. But each of those sets of brackets is a [US].
 
I think this is an editor issue. I went back through each one and positioned the cursor at the front of each IF and right arrowed to ensure that it moved past the "I" then moved it back using the left arrow and then backspaced till it moved back to the end of the previous line for each one. I noted that it was more backspaces than it should have taken. Something was there that was unseen. How it got there I'm not sure but I probably made it worse by copy lines.

I was using Notepad++. I've had issues before with the language coding not like this but showing weird characters from the formatting of PowerShell output and there've been other issues. Other editors I've tried VSCode and Sublime they all have quirks. Any one have a favorite editor?
 
I try to avoid such editor issues with using the same codepage "overall".

However: I also use Notepad++ ... so that's interesting for me too. WHAT exactly is your editor issue? I could try then too maybe.

As I saw there is one problem at least at the beginning of your line "37", right?
 
I try to avoid such editor issues with using the same codepage "overall".

However: I also use Notepad++ ... so that's interesting for me too. WHAT exactly is your editor issue? I could try then too maybe.

As I saw there is one problem at least at the beginning of your line "37", right?
I didn't think to hex view and no backup exists so I cannot answer. If I look up a heart it's like 2665. I could have copy and pasted code from a website and picked up something unexpected I think is the most likely way I got it.
 
More If problems! When the debugger hits the breakpoint at the top it stops as it should. However, when I get past the linear if and get into the structured if the current line goes to the closing paren above :Parm5OK. Somehow it's jumping out of the first if past a hard-coded breakpoint into the 2nd if structure not even the linear if "%~5".

Also this variable hovering only works part-time and I don't have any idea when and why but typically on a SET or IF statement. One example is that I do 3 sets at the top of a subscript and I can hover the first 2 and see a value but not the 3rd. On the If I don't even have that much to tell you.

breakpoint
If "%~4"=="" goto Finish

if %4 geq 0 (
If %4 leq 365 goto Parm4OK
) else (
Call LogFileLine.cmd %DBCallingName% "Invalid Full Backup Max Must Be 1-365" >> P:\Backup\BackupLogs\%Drive3Backup.log"
goto Finish
)

:Parm4OK


breakpoint
If "%~5"=="" goto Finish

if %5 geq 0 (
If %5 leq 365 goto Parm5OK
) else (
Call LogFileLine.cmd %DBCallingName% "Invalid Differential Backup Max Must Be 1-365" >> P:\Backup\BackupLogs\%Drive3Backup.log"
goto Finish
)
 
This time was different. It hit the breakpoint on line 71. When I clicked the step into it went to line 164. Out of curiosity I clicked step-into again. I wasn't expecting what I saw in the "command expansion" it was showing line 88 and it kept working through each line of the if and transferred control to Parm5OK line 94 at which point the current line was shown as the breakpoint on line 97. Now I didn't see it execute any of validation from line 72 to line 81 but it seems to have corrected.

In my console window I'm getting:
TCC: E:\SharedData\SharedBatchScripts\LogFileLine.cmd [57] Unknown command "breakpoint"
TCC: E:\Backup\BackupScripts\DriveBackup.cmd [26] Unknown command "breakpoint"
TCC: E:\Backup\BackupScripts\DriveBackup.cmd [42] Unknown command "breakpoint"
TCC: E:\Backup\BackupScripts\DriveBackup.cmd [52] Unknown command "breakpoint"
TCC: E:\Backup\BackupScripts\DriveBackup.cmd [71] Unknown command "breakpoint"
TCC: E:\Backup\BackupScripts\DriveBackup.cmd [84] Unknown command "breakpoint"
TCC: E:\Backup\BackupScripts\DriveBackup.cmd [97] Unknown command "breakpoihnt"
TCC: E:\SharedData\SharedBatchScripts\LogFileLine.cmd [57] Unknown command "breakpoint"

71:breakpoint
72:If "%~4"=="" goto Finish
73:
74:if %4 geq 0 (
75: If %4 leq 365 goto Parm4OK
76:) else (
77: Call LogFileLine.cmd %DBCallingName% "Invalid Full Backup Max Must Be 1-365" >> P:\Backup\BackupLogs\%Drive3Backup.log"
78: goto Finish
79:)
80:
81::Parm4OK
82:
83:
84:breakpoint
85:If "%~5"=="" goto Finish
86:
87:if %5 geq 0 (
88: If %5 leq 365 goto Parm5OK
89:) else (
90: Call LogFileLine.cmd %DBCallingName% "Invalid Differential Backup Max Must Be 1-365" >> P:\Backup\BackupLogs\%Drive3Backup.log"
91: goto Finish
92:)
93:
94::Parm5OK
95:
96:
97:breakpoihnt
98:If Not Defined [%6] goto Parm6OK
99:
100:IF /i [%6] == [y] (
101: Call LogFileLine.cmd %DBCallingName% "Forced Backup." >> "P:\Backup\BackupLogs\%2Drive%3Backup.log"
102: goto Parm6OK
103:) Else (
104: Call LogFileLine.cmd %DBCallingName% "Unknown parameter %6" >> "P:\Backup\BackupLogs\%2Drive%3Backup.log"
105: goto Finish
106:)
107:
108::Parm6OK
109:
110:
111:Call LogFileLine.cmd %DBCallingName% "Backup Device %2 Drive %3 Script Starting at %1 for a Maximum of %4 Full Backups and %5 Differential Backups. Forced Full Backup Setting %6" >> "P:\Backup\BackupLogs\%2Drive%3Backup.log"
112:
113:
114:breakpoint
115::: Save Parameters
116:set BSDBComputer=%2
117:Call LogFileLine.cmd %DBCallingName% "2 BSDBComputer=%BSDBComputer%" >> "P:\Backup\BackupLogs\%2Drive%3Backup.log"
118:set BSDBBackupDrive=%3
119:Call LogFileLine.cmd %DBCallingName% "3 BSDBBackupDrive=%BSDBBackupDrive%" >> "P:\Backup\BackupLogs\%2Drive%3Backup.log"
120:set BSDBMaxFullBackups=%4
121:Call LogFileLine.cmd %DBCallingName% "4 BSDBMaxFullBackups=%BSDBMaxFullBackups%" >> "P:\Backup\BackupLogs\%2Drive%3Backup.log"
122:set BSDBMaxDIfBackups=%5
123:Call LogFileLine.cmd %DBCallingName% "5 BSDBMaxDIfBackups=%BSDBMaxDIfBackups%" >> "P:\Backup\BackupLogs\%2Drive%3Backup.log"
124:set BSDBForceBackupType=%6
125:Call LogFileLine.cmd %DBCallingName% "6 BSDBForceBackupType=%BSDBForceBackupType%" >> "P:\Backup\BackupLogs\%2Drive%3Backup.log"
126:
127:
128:breakpoint
129:goto %1
130:
131::Start
132:
133:breakpoint
134::ArchiveBitCheck
135:Call LogFileLine.cmd %DBCallingName% "Archive bit check begin" >> "P:\Backup\BackupLogs\%2Drive%3Backup.log"
136:
137:Call LogFileLine.cmd %DBCallingName% "Archive bit check begin" > "P:\Backup\BackupLogs\%2Drive%3Attribute.log"
138:Call "C:\Program Files\PowerShell\7\pwsh.exe" "P:\Backup\BackupScripts\ArchiveBitCheck.ps1" %2 %3 >> "P:\Backup\BackupLogs\%2Drive%3Backup.log"
139:Call LogFileLine.cmd %DBCallingName% "Archive bit check end" >> "P:\Backup\BackupLogs\%2Drive%3Backup.log"
140:
141:::Undo
142:::goto finish
143:::goto ArchiveAttributeUpdate
144:
145:
146:breakpoint
147::Terabyte
148:Call LogFileLine.cmd %DBCallingName% "Terabyte backup start" >> "P:\Backup\BackupLogs\%2Drive%3Backup.log"
149:breakpoint
150:Call P:\Backup\BackupScripts\IFWBackupRotate.cmd %1 %2 %3 %4 %5 %6 >> "P:\Backup\BackupLogs\%2Drive%3Backup.log"
151:
152:
153:
154:breakpoint
155:If %BkupError% == 32 (
156: If not exist "P:\Backup\%2TerabyteError.Log" (
157: Call LogFileLine.cmd %DBCallingName% "BkupError=%BkupError% >> "P:\Backup\%2TerabyteError.Log"
158: Call LogFileLine.cmd %DBCallingName% "StableBit has no more space." >> "P:\Backup\BackupLogs\%2Drive%3Backup.log"
159: Call LogFileLine.cmd %DBCallingName% "The following backup has failed %2 Drive %3" >> "P:\Backup\BackupLogs\%2Drive%3Backup.log"
160: ) Else (
161: Call LogFileLine.cmd %DBCallingName% "Terabyte BkupError=%BkupError%. StableBit out of space." >> "P:\Backup\BackupLogs\%2Drive%3Backup.log"
162: Call LogFileLine.cmd %DBCallingName% "Attributes will not be updated. Skipping to finish" >> "P:\Backup\BackupLogs\%2Drive%3Backup.log"
163: goto finish
164: )
165:) Else (
166: If %BkupError% == 0 (
167: If exist "P:\Backup\%2TerabyteError.Log" (
168: del "P:\Backup\%2TerabyteError.Log"
169: Call LogFileLine.cmd %DBCallingName% "Deleted P:\Backup\%2TerabyteError.Log" >> "P:\Backup\BackupLogs\%2Drive%3Backup.log"
170: )
171: ) Else (
172: If %BkupError% == 137 (
173: Call LogFileLine.cmd %DBCallingName% "No backup needed, attributes not updated" >> "P:\Backup\BackupLogs\%2Drive%3Backup.log"
174: goto finish
175: ) Else (
176: If exist "P:\Backup\%2TerabyteError.Log" (
177: Call LogFileLine.cmd %DBCallingName% "Out-of-space file will not be deleted, attributes not updated" >> "P:\Backup\%2TerabyteError.Log"
178: Call LogFileLine.cmd %DBCallingName% "The following backup has failed %2 Drive %3" >> "P:\Backup\%2TerabyteError.Log"
179: goto finish
180: )
181: )
182: )
183:)
 
Last edited:
Back
Top