202

I'm adding this question after spending an entire day wrestling with this incredibly frustrating feature of the Windows 10 command prompt which made me think there was something wrong with my console application code. I hope it will help someone.

Issue: My console application seems to randomly stop running. What is going on?

Zoe
  • 27,060
  • 21
  • 118
  • 148
Shaun Rowan
  • 9,269
  • 4
  • 28
  • 52

4 Answers4

378

The issue ended up being a new feature of the windows 10 console. Under the default config, whenever you click on a command window in windows 10, it immediately halts the application process when it attempts to write to the console. When this happens, the command window has gone into "selection" mode.

You can tell it has happened because it will prefix the title bar of the command window with the word "Select" :

frozen command window

To get your program running again, you have to press escape or click somewhere else.

To get rid of this strange behavior, you can disable QuickEdit mode:

disable QuickEdit Mode

Zoe
  • 27,060
  • 21
  • 118
  • 148
Shaun Rowan
  • 9,269
  • 4
  • 28
  • 52
  • 50
    My god thanks you! Been dealing with this for a year LOL. Also you might have to disselect the option, CLOSE the terminal, and OPEN it again. At least that's how it works for me (otherwise it will auto enable it again.) – user2875289 Jun 28 '17 at 09:43
  • 1
    Thank you for showing how to disable it - while helpful in some circumstances, I really hate accidentally clicking in a terminal and not realizing for a minute or two why everything seems to be hanging. – Craig Otis Oct 02 '17 at 12:29
  • 8
    I had a multi hour compilation job that would keep freezing because of this. So glad you posted a solution! – Joel Feb 21 '18 at 23:50
  • 2
    Althought this answer helped disable freeze on click, scrolling the side bar freezes it as well. The previous behaviour was freeze while scroll bar was held and output was printed when you'd release the scroll bar. Any idea how to revert to hte old behaviour / unfreeze it? Esc or enter does not work. – quimnuss May 16 '18 at 18:23
  • 8
    that's a [very old feature](https://blogs.msdn.microsoft.com/oldnewthing/20070913-00/?p=25143/) for faster copy and paste. It's just that Windows 10 begins enabling it by default [How to disable right-click to paste in PowerShell?](https://superuser.com/q/1350963/241386) – phuclv Nov 09 '18 at 16:23
  • This setting does not seem to affect the console windows opened from Visual Studio, when you run a console program for debugging. Why is that? And what can I do about it? (except for disabling quick edit mode manually in code) – iko79 Mar 20 '19 at 13:56
  • @quimnuss Just bring the focus on the command prompt and hit [enter] – Mugen Apr 17 '19 at 02:10
  • 4
    "Feature not a bug" being the bane of users everywhere – tschwab Sep 27 '19 at 14:38
  • Thanks man.I was rerunning my programs coz i though it stuck and may be missed some data collection while the screen froze. – Shahir Ansari Nov 11 '19 at 10:22
  • omg, thank you! This has been bothering me for at least a year! I didn't have to restart my console after clicking OK. – David Rogers Nov 26 '19 at 21:32
  • wtf microsoft team was thinking with this great feature ? – Vitor Piovezam Feb 04 '20 at 22:41
  • 2
    Also see https://stackoverflow.com/questions/46567248/how-to-disable-user-selection-in-windows-console/46592932 for descriptions on how to disable this behaviour programmatically – Den-Jason Mar 06 '20 at 09:46
  • how do we navigate to this menu window? – Kalamalka Kid Jul 20 '20 at 16:51
  • 1
    Everyone: This is the dumbest %$&* I've ever seen. Windows: It's not a bug, it's a feature. Linux: ROFL – Sandwich Aug 27 '20 at 13:14
  • 1
    Even with the configuration values above, I still have a Java program that just stops with no error. – user2782 Sep 11 '20 at 15:29
  • Does not seem to work on Win Server 2016 – Dean Sep 25 '21 at 18:13
  • Win10: the same as @user2782 mentioned – abc May 09 '22 at 09:55
  • @KalamalkaKid Reference [this](https://www.statmodel.com/download/QuickEdit.pdf) – bittap Feb 05 '23 at 09:37
41

What I'd like to add here to Shaun Rowan's answer is that for it to work in all console windows you have to click "Defaults", instead of "Properties" and make your changes there, as described in this post.

iko79
  • 1,127
  • 10
  • 23
3

I faced this problem very recently where one of the users (who had Quickedit configured on his Command Prompt) was using a tool I developed in Java, and was getting the tool frozen while running it from command prompt.

Finally what solved the problem was to redirect the logging inside the batch script to a file as shown below:

@echo off
...
java.exe -jar mytool.jar

needed to be updated to

java.exe -jar mytool.jar > log.txt
Gibolt
  • 42,564
  • 15
  • 187
  • 127
Priyanku
  • 67
  • 2
  • Related https://superuser.com/questions/459609/what-does-it-do-exactly-if-i-click-in-the-window-of-cmd – rsinha Aug 14 '18 at 12:33
  • 2
    For developers, [this thread](https://stackoverflow.com/a/15751433/69809) might be interesting, you can disable this behavior programatically using `SetConsoleMode` (kernel32.dll). – vgru Mar 20 '19 at 21:36
1

It's possible to disable the annoying QuickEdit Mode programmatically by importing Windows' Kernel32.dll library and using the console API functions GetStdHandle, GetConsoleMode, and SetConsoleMode through your language's native interface (e.g., Java's JNI, Python ctypes).

Python with ctypes:

Short (disables everything except EXTENDED_FLAGS). Read SetConsoleMode documentation for more detail.

import ctypes

kernel32 = ctypes.windll.kernel32
kernel32.SetConsoleMode(kernel32.GetStdHandle(-10), 0x80)

Longer (disables QUICK_EDIT_MODE without altering other settings)

import ctypes
import time
import threading

# Constants
STD_INPUT_HANDLE = -10

# Enum for ConsoleModes
class ConsoleModes(ctypes.c_uint):
    ENABLE_PROCESSED_INPUT = 0x1
    ENABLE_LINE_INPUT = 0x2
    ENABLE_ECHO_INPUT = 0x4
    ENABLE_WINDOW_INPUT = 0x8
    ENABLE_MOUSE_INPUT = 0x10
    ENABLE_INSERT_MODE = 0x20
    ENABLE_QUICK_EDIT_MODE = 0x40
    ENABLE_EXTENDED_FLAGS = 0x80
    ENABLE_AUTO_POSITION = 0x100

# Import kernel32.dll functions
kernel32 = ctypes.windll.kernel32
GetStdHandle = kernel32.GetStdHandle
GetConsoleMode = kernel32.GetConsoleMode
SetConsoleMode = kernel32.SetConsoleMode

def disable_quick_edit_mode():
    std_in = GetStdHandle(STD_INPUT_HANDLE)
    mode = ctypes.c_uint()
    if GetConsoleMode(std_in, ctypes.byref(mode)):
        if mode.value & ConsoleModes.ENABLE_QUICK_EDIT_MODE:
            mode.value ^= ConsoleModes.ENABLE_QUICK_EDIT_MODE
            SetConsoleMode(std_in, mode)

def print_numbers():
    i = 0
    while True:
        time.sleep(0.3)
        print(i)
        i += 1

def main():
    disable_quick_edit_mode()
    threading.Thread(target=print_numbers).start()

if __name__ == "__main__":
    main()

Keep in mind that this code only runs on Windows. If you are writing software to be run on multiple operating systems, make sure to safeguard against errors.


Read More

C#:
Batch:
Maicon Mauricio
  • 2,052
  • 1
  • 13
  • 29