-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[dart:io] - stdin.readLineSync on Windows Powershell keeps waiting until something being typed #54588
Comments
https://github.com/dart-lang/sdk/blob/main/sdk/lib/io/stdio.dart#L56 is the code in Dart, it looks like it tries to support Windows, maybe powershell acts different from cmd 🤷 |
Yes powershell is exceptional for everything🥲 |
Thanks for looking at this @codesculpture! That's a pretty small amount of code, which should be possible to lift into a stand-alone Dart file and debug. Let me know if you need any help getting set up to debug. We're reachable on various Flutter related Discords including https://discord.gg/shorebird |
Hmm, the |
#include<windows.h>
#include<stdint.h>
#include<iostream>
bool ReadByte(int* byte) {
HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
uint8_t buffer[1];
DWORD read = 0;
BOOL success = ReadFile(h, buffer, 1, &read, nullptr);
if (!success && (GetLastError() != ERROR_BROKEN_PIPE)) {
return false;
}
*byte = (read == 1) ? buffer[0] : -1;
return true;
}
int main() {
int a;
ReadByte(&a);
std::cout << a;
} After Executing this, pressing enter in powershell would print (This is the reproduction of reading stdio as per the implementation of Edit: seems command prompt also works similarly to powershell, had a confusion here. Since there were new "cmd prompt" in windows 11 which i believe created using console mode whereas old one is not i guess. |
https://github.com/dart-lang/sdk/blob/main/sdk/lib/io/stdio.dart#L77-L87 I think this is what supposed to get executed but Is |
https://github.com/dart-lang/sdk/blob/main/runtime/bin/stdio_win.cc#L78
Sure |
From https://learn.microsoft.com/en-us/windows/console/getconsolemode This makes always I think we don't need to bother about |
//cc @brianquinlan |
The name itself |
@brianquinlan 🙂 just reminding you to take a look whenever u have spare time. |
If |
I was answering @codesculpture question on Discord which made me a bit curious about this problem. I could not reproduce this problem on my Windows 10 box even with newest Powershell. Eventually I have discovered that it only reproduces with Windows Terminal application, which I did not have installed. If you play with reading byte-by-byte from stdin in C under Windows Terminal you will immediately notice that it is utterly broken: sometimes you press enter and the reader gets CR LF, sometimes you press enter and the reader only gets CR and LF is mysteriously dropped. Which lead me to discover microsoft/terminal#16223 - so this is a bug in Windows Terminal and not in Dart. |
This is no longer an issue (tested in windows terminal v1.18.2) 🥳 |
If The above program executed on windows powershell, and if u press enter it would just move the cursor to next line and keep repeatedly do this until u type something, this not letting to pass empty input. Originally Founded from mason_logger felangel/mason#1189
The text was updated successfully, but these errors were encountered: