-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Ctrl-Z does not work in Windows #19914
Comments
I ran into this issue as well. Although lifthrasiir's code does not compile for me in the current version (
|
Triage: i do not have access to Windows to test this, but here's updated code that compiles:
|
I use a modern.ie VM.
That is, control-Z followed by enter does not terminate the program, but prints out |
This should be a pretty easy bug to knock out, so marking as E-easy and E-mentor as I'm willing to mentor it. This'll involve poking around I'm unfortunately not sure of a great way to add an automated test for this, but manual testing should work just fine! |
Can I pick this up? |
@RockyTV sure! Just let me know if you need any help! |
@alexcrichton I started working on this today, and I'm not sure what to do. I'd like to know what should I do if I remove the |
Yeah you'll probably want to remove this |
As I understand, there are two problems here: CTRL+Z and CTRL+C. On CTRL+C ReadConsole returns TRUE with empty buffer and with last error ERROR_OPERATION_ABORTED (source). So, it can be handled easily here. CTRL+Z on Windows works like CTRL+D on Unix, but Windows console functions doesn't handle it.
Thus, Rust must handle CTRLZ at some higher level, when processing the lines, I think. Any thoughts? |
cc @retep998 |
Ctrl + C should simply invoke the current console ctrl handler, whatever it is, which by default terminates the process, although it can be configured via SetConsoleCtrlHandler. I don't have any strong opinions on what we should do for Ctrl + Z. |
Need to check for Ctrl+D explicitly because of rust-lang/rust#19914
Need to check for Ctrl+D explicitly because of rust-lang/rust#19914
I removed the easy tag since there appear to be outstanding questions about what to do here. |
Windows. Fixes rust-lang#19914. Fixes read(), read_to_string(), read_to_end(), etc.
Ctrl-Z returns from Stdin.read() when reading from the console on Windows Fixes #19914. Fixes read(), read_to_string(), read_to_end(), etc. r? @alexcrichton
Fixed in #38274 when running from native Windows (cmd/PowerShell/etc). When running a Windows exe from Mintty (MSYS/Cygwin TTY), stdin & stdout are piped from/to Mintty. ReadFile() is used to read the stdin pipe and there seems to be no way to detect EOF, i.e. it doesn't return zero bytes when the user presses Ctrl+D. This is a known issue in Mintty. User workaround: Since winpty solves it, it's obviously possible. It would involve detecting Mintty, setting raw terminal mode and parsing the input. Alternatively, this post refers to hacks in git and ruby, but I don't understand what's happening there. Should implement this? If so, I'm happy to help with implementing and testing it on Windows, but I'll need a C guru to hold my hand. |
@elahn I'm not 100% privvy to all the issues in play here but if the handling code is reasonably small enough seems fine to put in the standard library. If it becomes quite large, however, or invasive, then we may wish to punt those issues to an external crate for now. |
As of
rustc 0.13.0-nightly (126db549b 2014-12-15 00:07:35 +0000)
this does not work: pressing Ctrl-Z then Return (a standard EOF sequence in Windows) simply printsOk(\x1a\x0d\x0a)
, and pressing Ctrl-C immediately terminates the process while printing apanic!
message.This is apparently a regression of #3948. According to the relevant code from CPython,
ReadConsoleW
may return an errorERROR_OPERATION_ABORTED
in both cases, and msvcrt (I think) will additionally issue a SIGINT for Ctrl-C within milliseconds. The current code handles none of them.The text was updated successfully, but these errors were encountered: