Windows – On Windows command line, how can I tell if a program is still running or is frozen

windowswindows-command-promptwindows-server-2016

I am running sqlcmd to import/execute a 2 GB SQL file that was created using SSMS's Generate Scripts command. It starts with typical output but the screen is quickly filled with…

...
(1 rows affected)
(1 rows affected)
(1 rows affected)
(1 rows affected)
(1 rows affected)
(1 rows affected)
...

I've left it running up to 20 minutes and I havent seen it conclude. I'm not sure if the program is still inserting new records and therefore continuing to output (1 rows affected) or if it is frozen somewhere in the script. On my Linux boxes, I can clear the terminal screen with a hotkey and see new output being generated.

Is there a way I can tell if the script is still executing or if it is frozen in Windows (Server 2016)?

Best Answer

This requires some preparation (doesn't help much, if the script is already running):

  1. Save the output into a file:

    • command > .\output.txt is a native method

    • Wintee copies standard input to standard output + file: command | wintee output.txt

  2. Monitor the file size e.g. with dir output.txt.

When the script is already running:

  • Monitor the database logs.

  • Use Resource Monitor.

  • If you are using Windows Server 2016 Desktop Experience or the script is otherwise running in a window, scrolling down moves the output forward. If the script has frozen, you'll get empty lines to be bottom of the window, but if new lines are flooding, you won't. You can test this with e.g. ping -t hostname.