Wild behavior from ANSI esq in batch variables #17667

Closed
opened 2026-01-31 05:49:32 +00:00 by claunia · 9 comments
Owner

Originally created by @jredfox on GitHub (Jun 9, 2022).

Windows Terminal version

1.12.10982.0

Windows build number

10.0.19044.1706

Other Software

java

Steps to reproduce

wt new-tab --focus --title "Test App 1.0.0" -d "C:\Users\jredfox\Documents\dev\OpenTerminal" -p "Command Prompt" cmd /c call "C:\Users\jredfox\AppData\Roaming\OpenTerminal\scripts\boot\boot.bat" "" "Test App 1.0.0" ",C:\Program Files\Java\jre1.8.0_333/bin/java, -Dot.l -cp ,C:\Users\jredfox\Documents\dev\OpenTerminal\bin, jml.ot.OTMain" "true"

the batch file

@ECHO OFF
IF NOT "%~1%" == "" (
   echo "%~1%"
   cls ::hotfix for Windows Terminal
)
title %~2%
set boot=%~3
set boot=%boot:,=^"% ::RE-MAP the boot command to double quotes
call %boot%
IF "%~4%" == "true" (
set /p DUMMY=Press ENTER to continue...
)
exit 0 ::Work around from a command prompt bug

It opens up like 20 tabs instead of one. with the ansi escape sequence in the batch variable string.

Expected Behavior

it opens up the my java program in wt with the colored output.

Actual Behavior

instead it opens up 20 tabs. it's having some wild behavior. switching to conhost.exe and cmd fixes the issue. I am going to work around this by changing the ansi escape to another character but this is just very silly

Originally created by @jredfox on GitHub (Jun 9, 2022). ### Windows Terminal version 1.12.10982.0 ### Windows build number 10.0.19044.1706 ### Other Software java ### Steps to reproduce `wt new-tab --focus --title "Test App 1.0.0" -d "C:\Users\jredfox\Documents\dev\OpenTerminal" -p "Command Prompt" cmd /c call "C:\Users\jredfox\AppData\Roaming\OpenTerminal\scripts\boot\boot.bat" "" "Test App 1.0.0" ",C:\Program Files\Java\jre1.8.0_333/bin/java, -Dot.l -cp ,C:\Users\jredfox\Documents\dev\OpenTerminal\bin, jml.ot.OTMain" "true"` the batch file ```batch @ECHO OFF IF NOT "%~1%" == "" ( echo "%~1%" cls ::hotfix for Windows Terminal ) title %~2% set boot=%~3 set boot=%boot:,=^"% ::RE-MAP the boot command to double quotes call %boot% IF "%~4%" == "true" ( set /p DUMMY=Press ENTER to continue... ) exit 0 ::Work around from a command prompt bug ``` It opens up like 20 tabs instead of one. with the ansi escape sequence in the batch variable string. ### Expected Behavior it opens up the my java program in wt with the colored output. ### Actual Behavior instead it opens up 20 tabs. it's having some wild behavior. switching to conhost.exe and cmd fixes the issue. I am going to work around this by changing the ansi escape to another character but this is just very silly
Author
Owner

@DHowett commented on GitHub (Jun 9, 2022):

This may be because wt treats ; as a subcommand separator. It's intended for use in composite commands, such as wt new-tab ; split-tab, but it can also be used to launch a number of programs side by side (wt cmd ; pwsh ; wsl).

Your best bet would be to escape them, or use -- as a WT command terminator (which may not work, honestly, I don't remember if it applies before or after ; splitting.)

@DHowett commented on GitHub (Jun 9, 2022): This may be because wt treats `;` as a subcommand separator. It's intended for use in composite commands, such as `wt new-tab ; split-tab`, but it can also be used to launch a number of programs side by side (`wt cmd ; pwsh ; wsl`). Your best bet would be to escape them, or use `--` as a WT command terminator (which may not work, honestly, I don't remember if it applies before or after `;` splitting.)
Author
Owner

@jredfox commented on GitHub (Jun 9, 2022):

but it's inside of the scripts "" is this not a bug?

@jredfox commented on GitHub (Jun 9, 2022): but it's inside of the scripts `""` is this not a bug?
Author
Owner

@DHowett commented on GitHub (Jun 9, 2022):

We should probably leave things in quotes alone. I suspect that we do, if the quote is sent to us. Quoted string parsing is one of the inconsistencies in shell command line handling across all of Windows, so I bet you'll get different results depending on what shell you call wt from.

@DHowett commented on GitHub (Jun 9, 2022): We should probably leave things in quotes alone. I suspect that we do, *if* the quote is sent to us. Quoted string parsing is one of the inconsistencies in shell command line handling across all of Windows, so I bet you'll get different results depending on what shell you call wt from.
Author
Owner

@jredfox commented on GitHub (Jun 9, 2022):

@DHowett like this it has the same result wt new-tab --focus --title "Test App 1.0.0" -d "C:\Users\jredfox\Documents\dev\OpenTerminal" -p "Command Prompt" -- cmd /c call "C:\Users\jredfox\AppData\Roaming\OpenTerminal\scripts\boot\boot.bat" "" "Test App 1.0.0" ",C:\Program Files\Java\jre1.8.0_333/bin/java, -Dot.l -cp ,C:\Users\jredfox\Documents\dev\OpenTerminal\bin, jml.ot.OTMain" "true" 

I am calling it from a program with each space being a separate param except the java command if that matters

@jredfox commented on GitHub (Jun 9, 2022): @DHowett like this it has the same result `wt new-tab --focus --title "Test App 1.0.0" -d "C:\Users\jredfox\Documents\dev\OpenTerminal" -p "Command Prompt" -- cmd /c call "C:\Users\jredfox\AppData\Roaming\OpenTerminal\scripts\boot\boot.bat" "" "Test App 1.0.0" ",C:\Program Files\Java\jre1.8.0_333/bin/java, -Dot.l -cp ,C:\Users\jredfox\Documents\dev\OpenTerminal\bin, jml.ot.OTMain" "true"  ` I am calling it from a program with each space being a separate param except the java command if that matters
Author
Owner

@jredfox commented on GitHub (Jun 9, 2022):

Also replacing the ; to , resulted in windows terminal instantly closing upon open. changing the ; to a non special character fixes it. nothing like this happens with batch files I think the issue is caused by not only � but also ; and it's ignoring the fact that it's inside a parameter

@jredfox commented on GitHub (Jun 9, 2022): Also replacing the `;` to `,` resulted in windows terminal instantly closing upon open. changing the `;` to a non special character fixes it. nothing like this happens with batch files I think the issue is caused by not only `�` but also `;` and it's ignoring the fact that it's inside a parameter
Author
Owner

@zadjii-msft commented on GitHub (Jun 9, 2022):

IIRC we had to do the subcommand splitting on ; before the -- parsing. The -- is handled by CLI11, but we hand each "subcommand" to CLI11 separately. This is definitely a tricky edge case. Case in point

wt nt -- foo.exe "bar;baz" "nt;nt ; nt"

Should that get split into subcommands? Probably, right? I know there are folks just doing wt nt;nt;sp in the wild, so we can't rely on spaces by the ;.

I'm not sure this could be fixed without some sort of slightly breaking change, but if anyone's got a good idea I'm open to it.

@zadjii-msft commented on GitHub (Jun 9, 2022): IIRC we had to do the subcommand splitting on `;` before the `--` parsing. The `--` is handled by CLI11, but we hand each "subcommand" to CLI11 separately. This is definitely a tricky edge case. Case in point ``` wt nt -- foo.exe "bar;baz" "nt;nt ; nt" ``` Should that get split into subcommands? Probably, right? I know there are folks just doing `wt nt;nt;sp` in the wild, so we can't rely on spaces by the `;`. I'm not sure this could be fixed without some sort of slightly breaking change, but if anyone's got a good idea I'm open to it.
Author
Owner

@jredfox commented on GitHub (Jun 9, 2022):

Linux has -e then a string command. Since you have the ability for multiple commands what about only slices it into new commands if the meta chars are outside of the quotes to begin with. It would work regardless of a single parameters or multiple called by a program. This includes but not limited to :;,

@jredfox commented on GitHub (Jun 9, 2022): Linux has -e then a string command. Since you have the ability for multiple commands what about only slices it into new commands if the meta chars are outside of the quotes to begin with. It would work regardless of a single parameters or multiple called by a program. This includes but not limited to :;,
Author
Owner

@zadjii-msft commented on GitHub (Jun 10, 2022):

#13264 is a little closer to the target here, so we're gonna use that one here. Thanks!

/dup #13264

@zadjii-msft commented on GitHub (Jun 10, 2022): #13264 is a little closer to the target here, so we're gonna use that one here. Thanks! /dup #13264
Author
Owner

@ghost commented on GitHub (Jun 10, 2022):

Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!

@ghost commented on GitHub (Jun 10, 2022): Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#17667