I am trying to execute a one line command including a for
loop by calling it via cmd /C
.
The command itself executes a for
loop to check if a service is running (in this case JBoss) and exits with an error code if it is stopped:
for /f "tokens=3 delims=: " %H in ('sc query JBossEAP7 ^| findstr "STATE"') do if "%H"=="STOPPED" exit /B 1
This works fine if I enter it in a cmd
window or use it in a .bat
file (if I substitute %
for %%
).
However, if I try to call it using cmd /C
(like this
cmd /C for /f "tokens=3 delims=: " %H in ('sc query JBossEAP7 ^| findstr "STATE"') do if "%H"=="STOPPED" exit /B 1
I get the error | was unexpected at this time
.
Can anyone point me towards a way how I can call this via cmd
without using a batch file?
cmd /C "YourCommandHere"
. I don't have mutch batch experience by try combining backticks into your params:`