Welcome!

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

SignUp Now!

found batch line continuation bug??

Jul
244
6
Maybe, maybe not, but it sure seems so? It probably has to do with my oddball choice of escape character.

But basically, both test4.bat and test5.bat should execute without error.

But test5.bat does not.

The only difference between the two is that i continue my "if" statement more than once in test5.bat.

It seems that *my* escape character can't be used twice on the same if statement.

(And yes, I've quintuple-checked that the escape character is actually the last character of each line it is used on)


Bash:
C:\>test4
C:\>test5
test5.bat [6]  Usage : IF [/I] [NOT] condition [.AND. | .OR. | .XOR. [NOT] condition ...] command
TCC: test5.bat [7]  Unknown command "foo"
TCC: test5.bat [10]  Unknown command ")"
TCC: test5.bat [13]  Unknown command ")"

Bash:
@echo off
REM test4.bat
set PARAM2=foo

    if "%PARAM2%" eq "skip_validation_existence" .or. "%PARAM2%" eq "skip_existence_validation" .or. ±
       "%PARAM2%" eq "skip_validation" (
                set SKIP_VALIDATION_EXISTENCE=1
                set USER_MESSAGE=%3$
            ) else (
                REM at this point, %2 must be a custom user message
                set SKIP_VALIDATION_EXISTENCE=0
            )

Bash:
@echo off
REM test5.bat
set PARAM2=foo

    if "%PARAM2%" eq "skip_validation_existence" .or. ±
       "%PARAM2%" eq "skip_existence_validation" .or. ±
       "%PARAM2%" eq "skip_validation" (
                set SKIP_VALIDATION_EXISTENCE=1
                set USER_MESSAGE=%3$
            ) else (
                REM at this point, %2 must be a custom user message
                set SKIP_VALIDATION_EXISTENCE=0
            )




1685707506625.png
 
Last edited:
And yes, my escape character choice is very weird

But that still doesn't explain why it would work once, but not twice. [Or does it?]

(And i've played around a lot with this. It really seems like I can only use batch line continuation once in mid-if statement.)

± ± ± ± ± ± ± ± ± ± ± ± ± ± ± ±

1685707866409.png
 
Last edited:
Pseudovariables and non-default separator/escape/parameter characters were deprecated back in v17; support for them has been gradually removed since then. I can guarantee you'll have continuing problems using them going forwards.

That said, what is the actual character (ASCII value) you're using for your escape character?
 
First, note that your batch file works fine using the default (i.e., only supported) escape character ^.

Second, it doesn't have anything to do with IF (line continuation is done before the line is passed to IF for parsing).

Third, the problem is with the Windows ReadFile API, which for some (undocumented) reason really doesn't like the unfortunate choice of ± as the continuation character. ReadFile is doing an oddball insertion of ± when it sees the ± character, which when it is converted to UTF16 for internal processing is bollixing up the line continuation.

So - not a TCC bug, and extremely unlikely that I am going to rewrite the Windows API to support that character as an (unsupported) line continuation character.
 
Haha fair enough! I'm surprised it took me almost 20 years to find consequences to this poor-in-retrospect choice!

Perhaps it should be disallowed in the input box but probably never in the history of humanity would it come up

I'm really happy to be bringing up my BAT files to modern speed here! Thank you!

---

side-note: I wanted to post my setprompt.bat that incorporates CPU usage into the tips & tricks forum, but apparently I don't have access to that forum.

1685711841039.png
 
This was valuable - I discovered while debugging your batch file that line continuation wasn't recognizing UTF8 characters in the next line when the batch file was flagged as UTF8. (Apparently not a common occurrence, as nobody's ever reported it).

I don't know that line continuation is particularly useful now that we don't have 80x25 monitors, but there's a lot of legacy batch files out there.

You should have permission to read/write any of the public forums - are you getting an error message?
 
It gets increasingly useful as age degrades vision, haha!

entropy -> aging -> worse vision -> larger fonts -> more need for line continuance :) :) :)

And wow, that's really awesome that this did result in a fix!
 
You should have permission to read/write any of the public forums - are you getting an error message?


It turns out I do have permission after all!


However, when i go here:


I see this:

1685718792160.png
 
That message simply confused me, sorry!
 

Similar threads

Back
Top