Terminal: wt does not handle newlines properly

Created on 16 Feb 2020  ·  3Comments  ·  Source: microsoft/terminal

Environment

Windows build number: Microsoft Windows [Version 10.0.18363.657]
Windows Terminal Version: 0.9.433.0

Steps to reproduce

Run this in PowerShell:

wt `
new-tab -p PowerShell` Core`;`
split-pane -H -p Windows` PowerShell `;`
split-pane -p cmd

Expected behavior

I should get a new tab split twice (three panes)

Actual behavior

  1. A new window
    2, Three tabs
  2. The second and third tabs have errors in them:
[error 0x80070002 when launching `
                                  split-pane -H -p "Windows PowerShell"']

and

[error 0x80070002 when launching `
                                  split-pane -H -p "Windows PowerShell"']

WORKAROUND

I eventually found that if I add a space after every ; then it works (except for #4618):

wt `
new-tab -p PowerShell` Core`; `
split-pane -H -p Windows` PowerShell `; `
split-pane -p cmd
Area-Commandline Help Wanted Issue-Bug Product-Terminal Resolution-External

All 3 comments

@Jaykul
I tried to add carriage return and line feed to the token separators for command line parsing in my tests for #4724. But when I tried to run your example it turns out that the back tick does never escape the new line unless it is preceded with a space. Regardless of the app you try to call. Any other character (not only the semicolon) directly in front of the back tick won't trigger escaping the new line in the PowerShell console. Can you confirm? I guess it's rather a PowerShell issue.
If you run your example from within a CMD shell (newline escaped using ^) it already works even without having \r and \n as token separators in the terminal source code.

wt ^
new-tab -p "PowerShell Core";^
split-pane -H -p Windows` PowerShell ;^
split-pane -p cmd

Actually, yeah, when I run the example from the original issue but put spaces in front of the newline-escaping backticks, I get this:

image

Looks like an issue in how powershell handles escaped newlines.

You're absolutely right. I am sorry -- I meant to come up with a pure-PowerShell example of that syntax (or to use echoargs.exe) so I could tell for sure what was going on, and I didn't do it before filing the issue. In case it will help with discussions with other PowerShell users like me -- who forget that PowerShell does _implied_ strings -- here's a simple example of what PowerShell is doing wrong:

Note: Write-Host takes any number of strings parameters

image

And of course, if you pass a weird string like that to a "native" command, PowerShell wraps it in quotes:

image

Basically, what happens is this:

  1. Because it's a shell, PowerShell does not _require_ quote marks around string parameters.
    2, PowerShell treats an escaped newline _inside_ a string differently than an escaped newline at the end of a command line (which is the line continuation)

When we don't leave a space between the `; (which we've escaped, so it's just a string) and the the newline, PowerShell is obliged to assume it's part of a string, and not a separate line-continuation mark. We can avoid this by separating it from the string _implicitly_ with a space (as I did in my "workaround" above), or explicitly, by putting quotes around the string:

wt `
new-tab -p "PowerShell Core" ";"`
split-pane -H -p "Windows PowerShell" ";"`
split-pane -p cmd
Was this page helpful?
0 / 5 - 0 ratings

Related issues

miniksa picture miniksa  ·  3Comments

warpdesign picture warpdesign  ·  3Comments

waf picture waf  ·  3Comments

TayYuanGeng picture TayYuanGeng  ·  3Comments

wkbrd picture wkbrd  ·  3Comments