Replies: 12 comments
-
This is likely due to the console input mode it inherits from PowerShell. Can you print out the console mode from the input handle? |
Beta Was this translation helpful? Give feedback.
-
Thanks, Dustun. Here's more of the code. GetConsoleMode(pcon->hIn, &dwMode); Funny! When I uncomment the wprintf line it works; i.e., it waits, even in a console. I only tested in a normal, conhost, console. It prints Mode: 0x1F7. The help page for SetConsoleMode() (7/12/2018) doesn't document 0x100 and 0x80. |
Beta Was this translation helpful? Give feedback.
-
It was not the wprintf() that got it working in a console, it was the Sleep(). Here, Sleep(50) is sufficient to make it work; Sleep(20) is not. If I run it from CMD in a console the mode is also 0x1F7 and it works without a Sleep(); |
Beta Was this translation helpful? Give feedback.
-
Ah, that’s interesting. I bet I know what’s happening! When you launch it from a shell in the traditional console, you pressing Enter generates a key down event and releasing it generates a key up event. I believe (?) that the application is getting launched and starting to wait between the key down and key up event. This means that the input handle immediately has a key up event waiting to be read on it. When you run from the run dialog, there’s no key events generated (for the console subsystem.) When you run it from Terminal, the key down and key up events are generated simultaneously—the release event is generated before you release the key. There’s nothing left for the application to read. You can likely help confirm this by reporting the first key event you read off the input handle using |
Beta Was this translation helpful? Give feedback.
-
(The Flush doesn’t necessarily help because of when the release event is generated. It probably empties the queue in the Terminal case though!) You can also test it in PowerShell by moving the sleep to before you launch the application: |
Beta Was this translation helpful? Give feedback.
-
And lastly, if you’re curious about the weird mode... Lines 363 to 369 in ae550e0 |
Beta Was this translation helpful? Give feedback.
-
It seems you're right. "Sleep 1; thing.exe" fixes it in PS and "delay 1 & thing.exe" fixes it in TCC. That INPUT_RECORD is a KEY_EVENT (that's as far as I got). I found the 0x80 flag (ENABLE_EXTENDED_FLAGS) in a routine I wrote many years ago to disable/enable QuickEdit. And I found 0x100 (ENABLE_AUTO_POSITION) in a header; it's easy to imagine what that indicates. The app writes a ruler on the current line and, after a keystroke, restores whatever might have been there. It's crude for now but works pretty well when running a Windows shell in WindowsTerminal ... and pretty badly in wsl/bash in WindowsConsole! I don't know how that happened. The ruler is a single string and it doesn't contain any newlines. I was going to make it a key-action that would run in the current tab/pane but I read the docs and figured out that you can't do that (and for good reason I imagine). |
Beta Was this translation helpful? Give feedback.
-
Interesting that the size is wrong. Might be reasonable to look at how you're printing the ruler and how you're measuring the size of the screen. For now, though, this question is getting closed as answered 😄 |
Beta Was this translation helpful? Give feedback.
-
Nothing fancy. The length of the ruler is csbi.dwSize.X and I print it with WriteConsole to a CONOUT$ handle. If, instead, I make the ruler an array of CHAR_INFOs and print it with WriteConsoleOutput if comes out OK in WT/bash. Here's another peculiarity with bash. I'm now using _getwch() to dismiss the ruler (it's so easy). Before that, I turn the cursor off (L"\x1b[?25l"). In any Windows shell, the cursor is off at the _gerwch(); in bash it's on. The same is true if I go back to using the WaitFor... and ReadConsoleInput, and in or out of WindowsTerminal. I don't know exactly what takes place when a Windows EXE is run in WSL but I figure (naively) that at some point it's solely a matter of the EXE and the console. So the differences in WSL are a bit surprising. |
Beta Was this translation helpful? Give feedback.
-
When you run a Windows executable from WSL, it actually runs inside a separate ConPTY session brokered by the inbox |
Beta Was this translation helpful? Give feedback.
-
Thanks! It's no big deal. I only run bash to test things. |
Beta Was this translation helpful? Give feedback.
-
Bitten by this again! I made a new and simple observation that I'd like to understand. I hope this adequately describes it.
Is there any documentation about which console-related Win32 API functions will not work as expected when run in WSL? |
Beta Was this translation helpful? Give feedback.
-
Environment
Microsoft Windows 10 Pro for Workstations
10.0.18363.1139 (1909)
WindowsTerminalPreview_1.4.2652.0_x64
Steps to reproduce
Use code like this in a CUI app.
// pcon->hIn is r/w handle to L"CONIN$"
FlushConsoleInputBuffer(pcon->hIn);
WaitForSingleObject(pcon->hIn, INFINITE);
Expected behavior
Behavior in a console (Conhost or OpenConsole) should be the same as in WindowsTerminal.
Actual behavior
When I run it from the Start\Run dialog, it waits for input. When run from Powershell in WindowsTerminal it waits for input. When run from Powershell in a console (provided by either Conhost.exe or OpenConsole.exe) it doesn't wait for input.
The difference may be my fault but I don't know how to fix it.
Beta Was this translation helpful? Give feedback.
All reactions