Batch bug that breaks the title bar

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jfl
Posts: 226
Joined: 26 Oct 2012 06:40
Location: Saint Hilaire du Touvet, France
Contact:

Batch bug that breaks the title bar

#1 Post by jfl » 15 Nov 2017 03:55

Hi,

I've just noticed a bizarre bug, which is new to me:
When you run a batch file in cmd.exe, the batch command line is displayed on the title bar.
And when the batch exits, the title bar changes back to the previous title. Ex: Administrator: Command Prompt
But I just found a case where the command line remains unchanged on the title bar after the batch exits!
And the next batch you run appears _after_ the one that remains.
If you run the faulty batch multiple times, the title bar message grows ever longer.

The key is to run a another batch as the second command after an &.

Ex:

t1.bat

Code: Select all

@echo off
setlocal
endlocal & t2.bat %*
t2.bat

Code: Select all

@echo This is %0 %*
Running (t1 Hello batch world) changes the title bar to:
Administrator: Command Prompt - t1 Hello batch world
then
Administrator: Command Prompt - t1 Hello batch world - t1 Hello batch world
etc...

Now if you change the last line in t1.bat to:

Code: Select all

endlocal & call t2.bat %* & exit /b
the bug disappears.

The endlocal is how I discovered the issue, but it's not the cause. If I change the line to a stupid:

Code: Select all

cd >NUL & t2.bat %*
the bug reappears.

Was this bug known already?
Any way to use and abuse it, like we like to do here? :wink:

npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: Batch bug that breaks the title bar

#2 Post by npocmaka_ » 15 Nov 2017 05:32

You are supposed to execute another batch file with CALL.
Without using CALL the control will be passed to the second batch file and when it ends the control will be not returned to the first one.

jfl
Posts: 226
Joined: 26 Oct 2012 06:40
Location: Saint Hilaire du Touvet, France
Contact:

Re: Batch bug that breaks the title bar

#3 Post by jfl » 15 Nov 2017 08:43

That was the purpose: My first batch prepares things for the second, and does not need it to return.
I hoped that _not_ using a call (which is legal) would speed things up a bit. I still don't know if it does, but it sure has a side effect on the title bar!

Post Reply