On my Windows10 laptop, I run a simple USB camera snapshot program, commandcam.exe (from https://batchloaf.wordpress.com/commandcam/), in a console .cmd script, which has one line:

FOR /l %%i in (1,1,1000000) DO FOR /F "usebackq delims==" %%G IN (`c:\systools\date "+%%Y%%m%%d-%%H%%M%%S"`) DO commandcam /devnum 2 /filename %%G.bmp /quiet & sleep 55

where date.exe and sleep.exe in my c:\systools were downloaded from http://unxutils.sourceforge.net Basically, the commandcam program creates files like 20210911-113214.bmp and sleeps 55 seconds and repeats. But once every few hours to a few days, my script freezes, with a blinking cursor. (This is absolutely unrelated to the problem that you accidentally click somewhere in the console to put it in text select mode. Note: my cursor always blinks)

I extensively checked all messages in the event viewer corresponding to the time it started to freeze. Found none relevant. Checked all processes with a start time corresponding to that time with a sysinternals tool pslist. Found only one, which is a new cmd.exe shown below (pid 22264 here):

cmd.exe (pid 16364)
  cmd.exe (pid 22264) <-- this one started when my cmd script froze

I notice when my script works, the parent cmd (16364) spawns commandcam, which takes a camera shot and exits, then the cmd spawns sleep; there will not be a new cmd process. When I see this new cmd, the script freezes. In case it helps, here's more info about this new cmd process:

pslist v1.28 - Sysinternals PsList
Copyright ⌐ 2000-2004 Mark Russinovich

Process and thread information for <my laptop>:

Name                Pid Pri Thd  Hnd   Priv        CPU Time    Elapsed Time
cmd               22264   8   1  136  83040     0:00:00.046     4:24:07.933
                      VM      WS    Priv Priv Pk   Faults NonP Page
                 4194303    6856   83040   84512     2561   11  133
 Tid Pri    Cswtch            State     User Time   Kernel Time   Elapsed Time
19500   9        94     Wait:UserReq  0:00:00.000   0:00:00.031    4:24:07.933

I notice that its private memory is kind of high (83040 KB). So I checked with Task Manager, which shows:

Mem active private ws 12K; private ws 12K; shared ws 6776K; Paged pool: 133K; NP pool: 11K; Handles: 136

There's great difference between pslist and Windows' Task Manager (only 12 KB). I think it's because pslist shows virtual private memory while Task Manager shows working set.

I don't know what else I can check. The "Wait:UserReq" process state is normal. By the way, I find that if I use Process Explorer and try to examine the thread call stack of this new cmd process, this process will be gone and commandcam will start, followed by sleep 55 seconds, ... i.e. everything will be back to normal. I don't know why. It's like checking the thread stack triggers something and it breaks the hang.

  • Try using && instead of &.
    – harrymc
    Sep 14 at 8:26
  • 1
    Sorry for being late. Unfortunately, commandcam started to be considered a virus. On the webpage for the program, other people reported the same problem. I'll see if I can get that sorted out, and then test the suggestion of using && in place of &. Thanks guys.
    – yong321
    Sep 18 at 3:37
  • I can no longer run the original commandcam.exe. But the virus scan doesn't complain about the 2012 version of it. So I've been running that old version. Surprisingly, this console program freeze problem no longer happens. I'm afraid the problem will be a mystery forever. Could it be due to the virus scan? (But why was it interrupted only after running for a few hours?) Due to a bug in the new version of commandcam? (But can a bug of a program stall the batch file loop in which this program, plus sleep.exe, runs?)
    – yong321
    Sep 22 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.