Hello,
I have a problem running a batch file I'm creating for Windows XP. At some stage it has to check whether a service is running or not. Let's assume that I type in the following command directly into a command prompt:
for /f "tokens=3" %H in ('sc query Spooler ^| findstr "STATE"') do echo %H
It runs flawlessly and outputs 1 or 4, depending on a service state. The problem starts when I put this command in a batch file, suitably modified by doubling % signs:
for /f "tokens=3" %%H in ('sc query Spooler ^| findstr "STATE"') do echo %%H
or any other for /f loop where sc is a command to process - even sc alone in a loop. When processing the command, cmd.exe processes start to multiply indefinitely and the batch execution hangs. I've tried both XP HE and Pro, English and Polish variants. Also, there is no such problem under Windows 8. For what I've checked, this issue only applies to sc - any other command I've tried in a loop ran without a problem. This command alone:
sc query Spooler ^| findstr "STATE"
also runs without a hassle. Has anyone encountered such a behavior? Any ideas?
Regards.