Sdk: Ctrl+C'ing out of a Dart script breaks Windows console

Created on 8 Mar 2017  路  6Comments  路  Source: dart-lang/sdk

In the following screenshot I executed the script test1.dart twice: The first time I let the script finish. The second time, I terminated the script in the middle of execution with Ctrl+C. When doing the latter, the Windows console breaks for subsequent commands that (try to) print to the console (see strange rectangular boxes in the screenshot).

syntax-error

I believe this is an undesired side-effect of the changes introduced to fix #28571.

/cc @zanderso

area-library area-vm customer-flutter library-io type-bug

All 6 comments

This is interesting: My default code page is 437. After Ctrl+C'ing out of a Dart script to break my console, chcp claims that I am still on code page 437. However, explicitly running chcp 437 again seems to fix the console.

At least according to this:

https://sourceforge.net/projects/chcp-advanced/

chcp changes both input and output codepage, but only displays the input code page. So if the Dart VM was changing the output codepage and not touching the input codepage, then that could explain what we're seeing.

Yeah, looks like that's what going on:

Code pages before Ctrl+C'ing out of a Dart script:

C:\Users\goderbauer> [Win32.NativeMethods2]::GetConsoleCP()
437
C:\Users\goderbauer> [Win32.NativeMethods2]::GetConsoleOutputCP()
437
C:\Users\goderbauer> chcp
Active code page: 437

Code pages after Ctrl+C'ing out of a Dart script:

C:\src\flutter [windowsVersion]> [Win32.NativeMethods2]::GetConsoleCP()
437
C:\src\flutter [windowsVersion]> [Win32.NativeMethods2]::GetConsoleOutputCP()
65001
C:\src\flutter [windowsVersion]> chcp
Active code page: 437

As you suspected, the output code page does not get resetted. Fixing that will probably fix this output problem.

Registering a signal handler for Ctrl+C and calling exit from there seems to be a work around for this problem:

ProcessSignal.SIGINT.watch().listen((_) {
    exit(-1);
});

I think we should handle this in the VM. It's weird to make you register a handler that just exits. I'll take a look at this after landing my other change.

I can confirm that this is fixed now! Thanks! \o/

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bergwerf picture bergwerf  路  3Comments

sgrekhov picture sgrekhov  路  3Comments

DartBot picture DartBot  路  3Comments

DartBot picture DartBot  路  3Comments

gspencergoog picture gspencergoog  路  3Comments