21

I'm in the middle of running a batch script that's taking a really long time and whose output is whizzing by at an unreadable rate. Is there a keyboard shortcut that allows you to pause the CMD console where it currently is to stop and read the output, and then re-start it again from the same place?

enter image description here

3
  • 7
    There's always CTRL-S. Then CTRL-Q to re-start.
    – BillP3rd
    Commented Nov 14, 2016 at 3:15
  • 1
    You can grab the scroll box and move it up, this will effectively pause the scrolling. You can then hit the down arrow key to move to the bottom of the buffer. Commented Nov 14, 2016 at 5:12
  • Isn't this the intended purpose of the "Scroll Lock" key?
    – TOOGAM
    Commented Nov 26, 2016 at 1:57

7 Answers 7

10

I didn't see this in the other answers.

I believe the serial control sequences of 'Ctrl-S' XOFF and 'Ctrl-Q' XON are the key sequences intended to solve the issue.

Please see;

XON/XOFF

3
  • 1
    I changed this to best answer for a few reasons. From research, the Pause/Break key on its own halts output, but not execution, which the other answer makes no mention of. Ctrl + Pause/Break must be used to halt execution, and this is slightly more cumbersome to type on most keyboards than Ctrl+S and Ctrl+Q (can be done with solely the left hand). That said, Ctrl + Pause/Break has the advantage that it doesn't need you to remember two extra keybindings, so both answers are good, I'd just like to see this one get the upvotes it deserves. Commented Mar 6, 2018 at 23:24
  • Note that although this answer sources a Unix/Linux question, the keybindings work fine on CMD.exe, at least on my Windows 7 OS. Commented Mar 6, 2018 at 23:26
  • 1
    @Hashim, thanks for sharing your research. Because you specifically asked how to pause output, I didn't consider (nor tested) this possibility, but it is nice to learn of. (Upvoted)
    – Marc.2377
    Commented Feb 15, 2019 at 21:31
23

Does your keyboard contain the Pause/Break key? It would serve well for this. Here's what it looks like, or at least used to:

Pause Break Key from Wikipedia

As an interesting bonus, this key can also be used during POST (Power On Self Test, which runs when the computer is turned on) to read output from the BIOS.

If you don't have that key, the combination Control + NumLock should work just the same, and there are other options depending on your manufacturer, according to Wikipedia.

To resume execution, press Enter.

4
  • Note on some keyboards you may have the a specific scroll lock key (usually marked ScrLk), which can serve a similar purpose. Commented Nov 14, 2016 at 5:14
  • 1
    @BurhanKhalid Well, I read on that link that it pauses output, but not execution, and this effect seems to not apply to the MS Windows console... but cool to know nevertheless
    – Marc.2377
    Commented Nov 14, 2016 at 5:19
  • 1
    With ping, it appears to stop execution. that's very odd, since ping is a discrete executable. additionally when paused, the ping.exe process remains in process explorer until it is allowed to complete. while paused, all its threads go into Wait:Executive, and doesn't seem to pulse periodically. Fascinating. Commented Nov 14, 2016 at 7:44
  • 3
    Another trick that i like to use is to mark some text with the mouse (i always have quickedit mode enabled). That halts output (and hence execution, since a program that writes to stdout waits until the stream is written), too.
    – ths
    Commented Nov 14, 2016 at 13:58
5

You can use "more" command. Though it is not exactly what you are looking for, it will limit screen output by a page.

3
  • 2
    This is the best solution because pausing the output at the right moment is pretty much impossible given the speed at which output is generally produced. For clarification you have to use a pipe after your command followed by MORE. For example NETSH HTTP SHOW SSLCERT | MORE
    – Vincent
    Commented Jun 13, 2018 at 17:43
  • 1
    Windows does not have 'more' native
    – KumarAnkit
    Commented Apr 16, 2019 at 14:59
  • @KumarAnkit It works for me in Win10: tasklist | more Commented Nov 2, 2023 at 13:00
3

Adding one more useful way for linux shells. (But maybe ok in windows too, try it!)

Presssing ctrl+z will hang the program. (Message: stopped)

To run it back again at his previous state, like if it were paused:

Type fg

Or for multiple usage: fg program_name_previously_ctrl+z_stopped`

2

On windows systems, if the output screen has enabled Quick Edit Mode (by Configuration) just click on the screen and select any part of the screen. The program will stop execution until you right-click on the screen to un-select. The screen can lose focus and it will continue to be frozen until you come back and right click on it. Beware that any content of the Clipboard, if any, can be turned over that screen when you right click on it.

1
  • To get quick edit mode: Open CMD window > right-click on title bar > Properties > Options tab > check QuickEditMode Commented Nov 2, 2023 at 13:33
1

There are a couple other methods here to add, if we're being thorough:

1) In addition to the Pause/Break button you can duplicate it's functionality by Using "CTRL+C".

This will cause the cmd script to pause and ask you if you would like to terminate it. Once you are done looking you can select "NO" (or perhaps yes if it suits you) and it will continue (Or exit, if you chose yes).

2) You can ALSO pause using the mouse by clicking your mouse cursor in the window to select text from the CMD Terminal.

You may have noticed this pausing output in the past and thought only the output to be delayed, however when scripts are running in interactive cmd instances you are actually pausing the execution of the code (The same as with "Pause/Break" and "CTRL+C" Methods).

However once the window loses focus, or you click to unpause things, the code execution will continue, and you have no option to end the code through this manner.

2
  • Wow, you guys are young. Never used serial terminals? Try Ctrl-s/Ctrl-Q
    – NetScr1be
    Commented Mar 7, 2018 at 0:08
  • Terminal emulator software generally implements XOFF/XON support as a basic function. This generally includes the system console on modern Unix and Linux machines, as well as GUI emulators such as xterm and the Win32 console.
    – NetScr1be
    Commented Mar 7, 2018 at 0:09
1

You can use ProcessExplorer or similar TaskManager program -> RMB on the process that's running inside the cmd (not the main cmd process itself) -> Suspend. Then whenever you want RMB on it again -> resume

Note: If you use ProcessExplorer to do this you might want to keep it open until you hit 'Resume'. If you instead close it down then reopen whenever you want to resume the process, I've noticed that sometimes it bugs out and does not recognize that the current state of that process is 'Suspended'; thus if you click 'Resume' in that case it might not resume it. But if you keep PE open until you want to resume the process again then all will work fine. If you're worried about the resources Process Explorer might consume while its open, you can simply do View -> Update Speed -> Paused.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .