Launching External Terminal Changes Ctrl+C Handling Of Programs
Type: Bug
Steps to reproduce:
- Launch VSCode (anywhere)
- Start new external terminal using Ctrl+Shift+C. I used Command Prompt in this case.
- Launch new program that can handle Ctrl+C
- Press Ctrl+C.
Expected result: Program handles Ctrl+C normally. Actual result: Program doesn't sees Ctrl+C at all.
A simple program that can handle Ctrl+C for this example is Python. However any app that handles Ctrl+C is affected (such as my simple WASAPI loopback program). Run this Python script within same terminal that VSCode creates at step 2.
try:
while True:
pass
except KeyboardInterrupt:
print("OK")
If Ctrl+C is pressed while that script is running:
- If the terminal/command prompt was launched by VSCode, pressing Ctrl+C does nothing.
- If the terminal/command prompt was launched by other means, pressing Ctrl+C prints "OK" and stops the infinite loop.
Reproducible both in insiders and stable (1.87.0).
VS Code version: Code - Insiders 1.88.0-insider (8c2b09c0443b94d75a73819ed35610f7e09375ae, 2024-02-28T18:53:20.095Z) OS version: Windows_NT x64 10.0.22631 Modes:
System Info
| Item | Value |
|---|---|
| CPUs | AMD Ryzen 7 4700U with Radeon Graphics (8 x 1996) |
| GPU Status | 2d_canvas: enabled canvas_oop_rasterization: enabled_on direct_rendering_display_compositor: disabled_off_ok gpu_compositing: enabled multiple_raster_threads: enabled_on opengl: enabled_on rasterization: enabled raw_draw: disabled_off_ok skia_graphite: disabled_off video_decode: enabled video_encode: enabled vulkan: disabled_off webgl: enabled webgl2: enabled webgpu: enabled |
| Load (avg) | undefined |
| Memory (System) | 15.39GB (7.43GB free) |
| Process Argv | --crash-reporter-id ca2e3ed8-bdf1-4e2a-b9d7-b651fe0eba6b |
| Screen Reader | no |
| VM | 0% |
A/B Experiments
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscod805cf:30301675
vsaa593cf:30376535
py29gd2263:30784851
c4g48928:30535728
962ge761:30841072
pythongtdpath:30726887
welcomedialog:30812478
pythonidxpt:30768918
pythonnoceb:30776497
asynctok:30898717
dsvsc013:30777762
dsvsc014:30777825
dsvsc015:30821418
pythontestfixt:30866404
pythonregdiag2:30926734
pyreplss1:30879911
pythonmypyd1:30859725
pythoncet0:30859736
pythontbext0:30879054
accentitlementst:30870582
dsvsc016:30879898
dsvsc017:30880771
dsvsc018:30880772
cppperfcontrol:30963551
d34g3935:30961436
edj9j583:30943796
fegfb526:30952798
7j2b6412:30951517
bg6jg535:30946824
ccp1r3:30958150
+1
It does not matter whether the external terminal is opened using a hotkey or using the command palette.
The internal terminal is not affected, i.e. Ctrl+C works there.
+1
Please fix this issue/provide us a solution. It used to work completely fine last year, have zero clue what happened.
A workaround that works for me is to run wt && exit after VSCode launches the external terminal. The new Windows Terminal tab will not have the issue. Unfortunately this only works if users set Windows Terminal as their default conhost.
it seems that spawning a process with detached set to true breaks Ctrl+C behavior
setting it to false in WindowsExternalTerminalService.spawnTerminal fixes it for me
https://github.com/microsoft/vscode/blob/588ec342a0ce15f8f049d66b41d6970a0ad46432/src/vs/platform/externalTerminal/node/externalTerminalService.ts#L71
funnily enough, that change was introduced in 9af00bdd834a4e9dc2f199251cdeeb4e9700f2f2, which was supposed to fix Ctrl+C not working
setting it to false in
WindowsExternalTerminalService.spawnTerminal
can't find that in vscode settings
it's not a setting, it's hard coded in the source code
you would have to compile vs-code yourself (or change the right detached:!0 in the compiled source (resources/app/out/main.js), the one whose arguments correspond the most with the source (without stdio arg). this way is of course not ideal)
change the right
detached:!0in the compiled source (resources/app/out/main.js)
It works, thanks!