Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2015-05-01
15:15 • Closed ticket [e66e444440]: Change Ctrl-C handling in Windows console plus 6... artifact: 8faa35d792 user: jan.nijtmans
14:51 • Ticket [e66e444440]: 3 changes artifact: 34af4b4b70 user: dgp
2015-03-19
10:46 • Ticket [e66e444440]: 3 changes artifact: c2460634c0 user: apnadkarni
10:41
Ticket [e66e444440]. Modified ReadConsoleBytes to handle Ctrl-C / Ctrl-Break and not return 0 bytes... check-in: 4368d9eefc user: ashok tags: trunk
09:00 • Ticket [e66e444440] Change Ctrl-C handling in Windows console status still O... artifact: 6a271bc48f user: jan.nijtmans
02:39 • Ticket [e66e444440]: 4 changes artifact: 1ecf5d36e1 user: apnadkarni
02:33 • New ticket [e66e444440]. artifact: 4e59793eb8 user: apnadkarni

Change Ctrl-C handling in Windows console

Closed / Fixede66e44444023ee253956979c54c905c6006f4540Created 12 years agoUpdated 12 years ago
Descriptionplain2015-03-19 02:33:21
Background: Windows allows Ctrl-C, Ctrl-Break etc. to be trapped by the application via the SetConsoleCtrlHandler call. Although Tcl itself does not support this in the core, extensions such as twapi do. However, a feature/bug/quirk in the tclWinConsole.c:ReadConsoleBytes function makes this trapping ineffective. As documented in MSDN, a Ctrl-C results in the Windows ReadConsole call returning successfully but with 0 bytes read. This gets funneled up the Tcl channel system as EOF on stdin and consequently the REPL loop exits.

The proposed change would be to change ReadConsoleBytes to detect this (GetLastError() returns ERROR_OPERATION_ABORTED) and simply repost the ReadConsole.

There will be no observed change in the default behaviour because the default OS handler (run in a separate thread) will still exit the process on a Ctrl-C. However, applications that use extensions to trap Ctrl-C by replacing the default handler will work as expected.

The proposed change is in the Windows-specific code and will not affect other platforms.

Reference: http://stackoverflow.com/questions/27903208/tcl-and-ctrl-c-in-windows-console/27904696#27904696
Referenced by1
  • 4368d9eefcTicket [e66e444440]. Modified ReadConsoleBytes to handle Ctrl-C / Ctrl-Break and not return 0 bytes indicating EOF for those cases. check-in2015-03-19 10:41:28
apnadkarniplain2015-03-19 02:39:13
Changed to Bug because rethinking the issue, treating the Ctrl-C as EOF seems just wrong.
jan.nijtmansplain2015-03-19 09:00:58
This change looks good to me. Please go ahead and either provide a patch or just commit it. I will be happy to apply the patch and/or to test it.
apnadkarniplain2015-03-19 10:46:31
Committed fix in checkin [4368d9eefc]
dgpplain2015-05-01 14:51:32
status?
jan.nijtmanswiki2015-05-01 15:15:18

Fix in [4368d9eefc] looks fine to me, so closing.

Log in (anonymous is fine) to add a comment.