67

Problem:

For some reason once in a while my command prompt would hang until I press a random key, and it would continue operation as if nothing happened.

Occurrence:

This happens when I am running a long operation (such as building/compiling some code). When it hangs, it gives no indication of what's going on nor does it prompt me to press any key.

Description:

  1. After a couple minutes, the terminal stops printing out the progress, and gets stuck.
  2. I had thought that it was simply stuck on a very lengthy portion of the compile process, but after a few hours it was still stuck on the exact same place.
  3. I pressed a random key, and it suddenly jumped straight back and continued spewing out progress indicators and continued working.

After this, similar events have happened many times during lengthy processes, such as copying files.

This has happened on multiple devices running windows 7. It has also occurred on Ubuntu using bash shell.

phuclv
  • 26,555
  • 15
  • 113
  • 235
Razor Storm
  • 959
  • 3
  • 12
  • 22
  • 2
    Any of these machines set to sleep at all? – Windos Jul 18 '11 at 23:04
  • No, the machine doesn't go to sleep, just the terminal apparently. The machines also don't have sleep or any low power modes enabled. And have never once gone into sleep mode in their entire life time (Since I bought/built them) – Razor Storm Jul 18 '11 at 23:46
  • 1
    It sounds like you're having the same issue from two completely different environments (Linux and Windows). So you might ask what do these two things have in common? Is it the same script/code? Copying to the same server? – Nixphoe Jul 19 '11 at 01:54
  • This has happened many times over several years on completely different tasks. Some things Ive done that I remember: making a build at work, copying some files locally (robocopy on windows and cp on linux), rsync on remote servers, running batch scripts, etc – Razor Storm Jul 19 '11 at 04:45
  • 3
    Those who are wondering if it is still an issue,Yes ! – Thakur Karthik Dec 31 '19 at 06:52
  • 7
    Still a problem in 2020 – Bakhshi Jun 17 '20 at 04:08
  • I think this is going to become one of humanity's greatest unsolved mysteries – Razor Storm Jun 24 '20 at 05:21
  • Same problem in 2021. Windows 10 Home, 20H2. Does anyone have a work around? – horaceT Sep 29 '21 at 16:56
  • Does this answer your question? [prevent sleep in scripts](https://superuser.com/questions/90415/prevent-sleep-in-scripts) – Ramhound Sep 29 '21 at 22:51
  • Most of the time it's because mark mode has been enabled and you accidentally clicked inside the console: [Command prompt gets stuck and continues on enter key press](https://stackoverflow.com/q/13599822/995714) – phuclv Oct 09 '21 at 12:43
  • 3
    Still a problem in 2022! – andreagalle Apr 01 '22 at 14:49
  • @Bakhshi not at all if you use the new Windows Terminal, or disable quickedit in the old terminal – phuclv Jun 29 '23 at 05:43

3 Answers3

38

I have experienced the same issue. Answers here and here indicate this is likely an issue with Quick Edit mode in the console. If it intercepts stray mouse clicks, or if clicks get passed erroneously through RDP, for instance, it can unintentionally pause the script. You can right-click the menubar and edit properties to turn off Quick Edit mode. That, of course, makes it more difficult to copy and paste out of the CMD window.

Tim D
  • 489
  • 4
  • 6
  • 1
    I have quick edit mode off, and experience this often in node. No issues on linux. But windows will seem to pause, until I ctr C once. This continues the node process. Seems like it would kill the process if it was truly hanging. – edencorbin Sep 05 '18 at 23:14
  • I have disabled quick edit mode so will keep an eye. My solution is to resize my cmd prompt, or power shell window a bit - to get the npm script to continue. Very strange indeed. – shanehoban Feb 28 '19 at 23:07
  • 8
    I've seen this for 20 years in windows. It has appeared and disappeared many times... I think its Microsoft not doing proper regression testing, because it comes and goes every few years – gunslingor Oct 11 '19 at 16:38
  • 1
    Experiencing this regularly these days when running python3.7 scripts in powershell, very annoying :( – Loknar Dec 18 '19 at 12:22
2

The old Windows console has a separate mode called "mark mode" for selecting text. In that mode the screen will be frozen for ease of selection

Mark mode

If QuickEdit 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

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

But the better solution is to use Windows Terminal which is significantly better, faster, more featureful and more powerful

See also

phuclv
  • 26,555
  • 15
  • 113
  • 235
-1

I found this answer, and it works for me on Windows 10 20H2. The trick seems to be,

powercfg -change -standby-timeout-ac 0
horaceT
  • 115
  • 1
  • If you found a question, with an answer that answers this question, you should flag it as a duplicate. We try to avoid answers that just point to another answer. – Ramhound Sep 29 '21 at 22:51
  • 1
    Until someone flags the question as a duplicate, it's still good to have an answer here. It's a 10 year old question with 40k views and otherwise no clear answer so far. The downvotes on a potential solution make no sense for someone coming from Google. – Blaisem Oct 29 '21 at 11:53