Why is my command prompt freezing on Windows 10?
Asked Answered
G

6

205

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?

Grunion answered 24/11, 2015 at 0:46 Comment(2)
Also you need to Press Enter to continue running the programDykstra
What does it do exactly if I click in the window of cmd?Elevated
G
383

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

Grunion answered 24/11, 2015 at 0:46 Comment(18)
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.)Heterodyne
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.Mielke
I had a multi hour compilation job that would keep freezing because of this. So glad you posted a solution!Rest
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.Urethra
that's a very old feature 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?Elevated
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)Ilyssa
@Urethra Just bring the focus on the command prompt and hit [enter]Bathurst
"Feature not a bug" being the bane of users everywhereEleonoraeleonore
Thanks man.I was rerunning my programs coz i though it stuck and may be missed some data collection while the screen froze.Zavras
omg, thank you! This has been bothering me for at least a year! I didn't have to restart my console after clicking OK.Gutow
wtf microsoft team was thinking with this great feature ?Stilt
Also see #46567748 for descriptions on how to disable this behaviour programmaticallyExperimentalism
how do we navigate to this menu window?Valuable
Everyone: This is the dumbest %$&* I've ever seen. Windows: It's not a bug, it's a feature. Linux: ROFLWisconsin
Even with the configuration values above, I still have a Java program that just stops with no error.Czechoslovakia
Does not seem to work on Win Server 2016Computation
Win10: the same as @Czechoslovakia mentionedDulcimer
@KalamalkaKid Reference thisSatrap
I
43

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.

Ilyssa answered 21/3, 2019 at 15:57 Comment(1)
Even with "Defaults" cmd still freezes...Dulcimer
I
4

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
Increate answered 23/3, 2018 at 13:49 Comment(2)
Related superuser.com/questions/459609/…Alluvial
For developers, this thread might be interesting, you can disable this behavior programatically using SetConsoleMode (kernel32.dll).Wino
C
3

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:
Congratulatory answered 8/8, 2023 at 0:56 Comment(2)
Or we could change the quickedit registry key from 1 to 0Iila
@Iila Which is permanent and applies to all console windows, not just the specific one the behaviour causes problems in. QickEdit mode can be useful otherwise and should not be globally changed by a script. So for these cases doing it programmatically is helpful. And otherwise the GUI solution is faster.Homochromatic
I
1

I know this is an old question, but the provided answers are overcomplicated. This behavior can be changed with a single registry value.

In CMD prompt type the following:

REG add "HKCU\Console" /v QuickEdit /t REG_DWORD /d 0 /f
Iila answered 10/2, 2024 at 14:37 Comment(0)
N
0

I must point out that the application is actually not "halted" or "paused", it's only because the console output stream is blocked whenever you click on the command window, and if you see the whole application pausing, it's because these programs don't implement multithreading and non-blocking IO correctly.

You can easily verify this by writing a multi-threading application. For example, the following Java application shows a login dialog and continues to output text on the console. When the console blocks, you can still interact with the GUI.

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField; 
public class SwingLoginExample {
    
    public static void main(String[] args) { 
        new Thread(() -> {
            var i = 0;
            while (true) {
                i++;
                System.out.println("Hello World! " + i); // System.out.println is a blocking method in java
            }
        }).start();

        JFrame frame = new JFrame("Login Example");
        // Setting the width and height of frame
        frame.setSize(350, 200);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


        JPanel panel = new JPanel();    
        frame.add(panel);
        placeComponents(panel);

        frame.setVisible(true);
    }

    private static void placeComponents(JPanel panel) {
        panel.setLayout(null);


        JLabel userLabel = new JLabel("User:");

        userLabel.setBounds(10,20,80,25);
        panel.add(userLabel);

        JTextField userText = new JTextField(20);
        userText.setBounds(100,20,165,25);
        panel.add(userText);


        JLabel passwordLabel = new JLabel("Password:");
        passwordLabel.setBounds(10,50,80,25);
        panel.add(passwordLabel);


        JPasswordField passwordText = new JPasswordField(20);
        passwordText.setBounds(100,50,165,25);
        panel.add(passwordText);

        JButton loginButton = new JButton("login");
        loginButton.setBounds(10, 80, 80, 25);
        panel.add(loginButton);
    }

}

You should always avoid calling print() or similar methods directly; if the console responds slowly, your program will be slowed down as a result. Create a thread to perform the print() task, or use a non-blocking alternative.

Nutritive answered 4/12, 2023 at 7:31 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.