請大各位大大:
sc query state= all |find "Oracle"
正常顯示結果
for /f "tokens=2 delims= " %i in ('sc query ^|find "Oracle"') do (
echo %i
)
也有出現預期的結果
for /f "tokens=2 delims= " %i in ('sc query state= all ^|find "Oracle"') do (
echo %i
)
這樣就不行了
因為有需求,一定要加上state= all
但多了state= all就失敗,不曉得是什麼原因...
請各位高手幫忙!!!
因為 = 和 | 都是屬於要加跳出字元的。
參考:https://lnpcd.blogspot.com/2012/09/14.html
for /f "tokens=2 delims= " %i in ('sc query state^= all ^|find "Oracle"') do (
echo %i
)
或
for /f "tokens=2 delims= " %i in ('sc query Oracle ^|findstr SERVICE_NAME') do (
echo %i
)