Terminal Escape Sequences expected behavior?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
atfon
Posts: 178
Joined: 06 Oct 2017 07:33

Terminal Escape Sequences expected behavior?

#1 Post by atfon » 22 Nov 2021 07:23

I've noticed a discrepancy between the behavior of certain terminal escape sequences when another instance of cmd.exe or powershell is invoked. I'll provide a couple brief examples.

1. Let's say you want to stop the cursor from blinking:

Code: Select all

@echo off
setlocal enabledelayedexpansion
for /f %%e in ('echo prompt $E^|cmd') do set "\e=%%e"
echo Hi
echo %\e%[?12l
powershell /command "Get-Host | Select Version"
cmd /k echo Hi
In this instance, the cursor stops blinking and remains regardless if I invoke cmd.exe or powershell.

2. Lets say you want to change the title and Run the script as Administrator:

Code: Select all

@echo off
setlocal enabledelayedexpansion
for /f %%e in ('echo prompt $E^|cmd') do set "\e=%%e"
for /f %%g in ('%__APPDIR__%forfiles.exe /p "%~dp0." /m "%~nx0" /c "cmd /c echo 0x07"') do set "bel=%%g"
echo %\e%]0;Test Title%BEL%
pause
powershell /command "Get-Host | Select Version"
or

Code: Select all

@echo off
setlocal enabledelayedexpansion
for /f %%e in ('echo prompt $E^|cmd') do set "\e=%%e"
for /f %%g in ('%__APPDIR__%forfiles.exe /p "%~dp0." /m "%~nx0" /c "cmd /c echo 0x07"') do set "bel=%%g"
echo %\e%]0;Test Title%BEL%
pause
cmd /k echo Hi
In each case here, invoking cmd.exe or powershell changes the title to include Administrator.

Is that expected behavior for a Operating System Command (OSC) sequence as opposed to a Control Sequence Introducer (CSI)?

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Terminal Escape Sequences expected behavior?

#2 Post by aGerman » 22 Nov 2021 10:51

I believe it's intented to always have Administrator in the title if you run it elevated. It's rather UB or a bug if you are able to bypass it.
viewtopic.php?f=3&t=9931&p=63866#p63776

FWIW There's a PR for the terminal app which turns the Administrator title into a shield icon instead. Already in the 1.12 preview.
https://github.com/microsoft/terminal/pull/11224

Steffen

atfon
Posts: 178
Joined: 06 Oct 2017 07:33

Re: Terminal Escape Sequences expected behavior?

#3 Post by atfon » 22 Nov 2021 11:39

aGerman wrote:
22 Nov 2021 10:51
I believe it's intented to always have Administrator in the title if you run it elevated.
So, you're suspicion is that the sequence provided here is not supposed to remove the word "Administrator" from an elevated batch script?

https://docs.microsoft.com/en-us/window ... ndow-title

The current behavior [version Version 10.0.19044.1348 on my system] is that it does, until another command process or powershell is invoked. There may be other situations which causes the title to revert, but I've seen it in those two.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Terminal Escape Sequences expected behavior?

#4 Post by aGerman » 22 Nov 2021 12:26

I didn't find any official statement. However, apparently the only reason why the Administrator title exists is to warn/remind the user. The fact that even a successfully updated title is turned back into the Administrator title at the next opportunity makes me believe that this is the intended behavior. Guessing might not be satisfactory though. Consider to file a new issue over in the terminal repository and see what the core team replies.

Steffen

Post Reply