0

I have a batch file, that calls a WMIC command. The WMIC command is inside a for loop.

Calling this batch file results in indefinite hang, and it seems to hang for more than 2 to 3 hours, only way to get out is by terminating the process by pressing CTRL+C.

The WMIC command is:

FOR /F "skip=1 tokens=1-6" %%A IN ('WMIC Path Win32_LocalTime Get Day^,Hour^,Minute^,Month^,Second^,Year
/Format:table')

The script hangs only when it is executed on windows server 2003, it works perfectly fine on other operating system.

The server that has server 2003 also has AMD processor, is this the cause? or is there something else that I am missing?

By the way the script is called in the line:

 %LOGMESSAGE%  do something . 

And LOGMESSAGE variable is set to call the script containing the WMIC command as follow:

 set LOGMESSAGE=call path_to_the_script\WMIC.cmd

Any suggestion is very much helpful, thanks a ton in advance.

spaniard89
  • 307
  • 1
  • 6
  • 18
  • maybe is a silly question, but, does the `wmic path ...` command work from command line? and What is inside the for loop? – MC ND Nov 28 '13 at 17:41
  • @MCND yeah it does, the whole batch file works flawlessly when called on the CMD separately. In the for loop the date and time are sorted and are written on a log file. – spaniard89 Nov 28 '13 at 22:28
  • When testing the cmd at a prompt, you need to use the same permissions as when the bat is launched. It could be that the command needs administrator permissions and when you are testing it you are in an administrator account. Test this: `WMIC Path Win32_LocalTime Get Day,Hour,Minute,Month,Second,Year /Format:table` – foxidrive Nov 29 '13 at 00:04
  • @foxidrive The above command seems to work, so is the command with ^ symbol after day, month and time, everything works flawlessly on cmd but in a batch file it just hangs on this line. – spaniard89 Nov 29 '13 at 08:33
  • Ok. We can't see the actual command it is executing - that is where it must be getting stuck. – foxidrive Nov 29 '13 at 08:37
  • BTW the `/Format:table')` is on the end of the command isn't it? It's not on the next line by itself? – foxidrive Nov 29 '13 at 08:38
  • @foxidrive That's not an issue, cause I also kept it on the same line, still the issue didn't solve. – spaniard89 Nov 29 '13 at 11:55
  • We can't see the actual command it is executing - that is where it must be getting stuck. – foxidrive Nov 29 '13 at 11:59
  • @foxidrive `' START "" /W CMD /C WMIC Path Win32_LocalTime Get Day^,Hour^,Minute^,Month^,Second^,Year /Format:table'` works, but the value of time, date and hour and others are somehow not passed from child window to parent window. Any idea why? – spaniard89 Nov 29 '13 at 13:37
  • @foxidrive As this is a new issue, I created a new post at http://stackoverflow.com/questions/20287297/batch-file-start-w-cmd-c-doesnt-seem-to-work-inside-a-foor-loop – spaniard89 Nov 29 '13 at 13:50

1 Answers1

1

This works for me:

FOR /F "skip=1 tokens=1-6" %%A IN ('echo. ^| WMIC Path Win32_LocalTime Get Day^,Hour^,Minute^,Month^,Second^,Year /Format:table')

snat
  • 11
  • 2
  • It is a feature of the WMIC that it sometimes waits for user input. The use of in the line above gets around this issue and allows the command to complete – FrinkTheBrave Nov 02 '16 at 17:06