Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command prompt gets stuck and continues on enter key press

Does anyone come across a scenario when the command prompt is running a process and then it gets stuck and the process is also sleeping. Then when we press Enter key in the cmd window the process continues.

Is there any way to avoid this? or can this be handled??

like image 209
Sangram Mohite Avatar asked Nov 28 '12 07:11

Sangram Mohite


People also ask

Why does command prompt get stuck?

One reason why you're unable to run the command prompt on your computer is that there might be a third party software causing conflict to it. For us to assist you, we suggest that you start your PC in safe mode.

Why is my command prompt freezing on Windows 10?

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.

How do you hit enter in cmd?

Press Win + R to open the Run box, then type "cmd" and hit Enter to open it.

How do I stop a command prompt from running?

Then we hit Ctrl+C to terminate the execution.


2 Answers

The other answers are wrong! The Windows console has a separate mode called "mark mode" for selecting text. In that mode the screen will be frozen, texts will go into the buffer and if the buffer is full the running process will be blocked

Mark mode

If quick edit mode is enabled (by default it's disabled in older Windows but enabled in Windows 10) then clicking inside the console window will activate mark mode and result in what you observed

It's very easy to accidentally click the console and stop the command. When you press Enter or Esc the selected text will be copied to clipboard and mark mode will be exited, therefore the process will run again. Priority is absolutely irrelevant here because if the buffer is full then the process is blocked forever until you exit mark mode, regardless of the priority. The console does nothing to change the priority when there are some inputs. Try opening an app that outputs a lot of data in the highest priority and click the console, the app will still be blocked indefinitely even if the CPU is in idle

Here's an example of QuickEdit mode setting in Windows 8 console:

cmd

To fix this you can disable QuickEdit mode if you don't need it. In this case copying will be more troublesome because you must open the context menu, select Edit > Mark. You can also disable QuickEdit mode by setting ENABLE_QUICK_EDIT_MODE with SetConsoleMode() if you're writing your own console application

See also

  • How and why does QuickEdit mode in Command Prompt freeze applications?
  • What does it do exactly if I click in the window of cmd?
  • Turn off Windows 10 console "Mark" mode from my application
like image 112
phuclv Avatar answered Oct 04 '22 20:10

phuclv


If other processes are sucking all the cycles and have a higher prio, then your process might be stopped. A user input might just give it a prio boost, so it starts again. See Microsoft Docs at https://docs.microsoft.com/en-us/windows/win32/procthread/priority-boosts for more information.

like image 40
cxxl Avatar answered Oct 04 '22 21:10

cxxl