darqious Posted March 12, 2017 Posted March 12, 2017 (edited) 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. Edited March 13, 2017 by darqious
jaclaz Posted March 12, 2017 Posted March 12, 2017 It works here (the batch I mean) just like the command line version, (XP PRO SP2 Italian), it must be something specifically on your machines, but really cannot say what it could be. The output of the simple command here is this: Quote C:\batches>sc query Spooler SERVICE_NAME: Spooler TYPE : 110 WIN32_OWN_PROCESS (interactive) STATE : 4 RUNNING (STOPPABLE,NOT_PAUSABLE,ACCEPTS_SHUTDOWN) WIN32_EXIT_CODE : 0 (0x0) SERVICE_EXIT_CODE : 0 (0x0) CHECKPOINT : 0x0 WAIT_HINT : 0x0 Try this (but I don't think that it will change anything: Quote FOR /F "tokens=* delims=" %%H IN ('sc query Spooler ^| find "STATE"') DO CALL :do_echo %%H GOTO :EOF :do_echo ECHO %* ECHO %3 jaclaz 1
darqious Posted March 13, 2017 Author Posted March 13, 2017 (edited) Uhm... After struggling with it for the last 3 days it's a shame to tell, but... for testing purposes I had to give my batch file any name, and my first thought was... sc.cmdSC.freaking.cmd And I named it like that every time I tested it on XP. ...please don't. I'll die by myself. Problem solved. Thanks and regards. Edited March 13, 2017 by darqious
jaclaz Posted March 13, 2017 Posted March 13, 2017 8 hours ago, darqious said: Uhm... After struggling with it for the last 3 days it's a shame to tell, but... for testing purposes I had to give my batch file any name, and my first thought was... sc.cmdSC.freaking.cmd And I named it like that every time I tested it on XP. ...please don't. I'll die by myself. Problem solved. Thanks and regards. Nice one, I would have never thought of that, something to remember, particularly when one is tired and/or hits a roadblock and insists on it head down, without taking some time out for a walk ... Haopy everything is well now. jaclaz 1
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now