用于检查“状态”的 For 循环;某些窗户的服务
services.txt
包含:-
Plugplay
假脱机程序
dhcp
我想检查文件 services.txt
中指定的某些服务的状态。我为此使用 for 循环。
@echo off
for /f %%a IN ('type services.txt') do call :chkservice %%a
goto :eof
:chkservice
sc query %a%
我得到的输出相当于命令 sc query
的三倍(我猜),而不是获取三个指定服务的输出。
为了调试,我尝试检查变量 a
是否正确获取值,并尝试了此版本的代码:-
@echo off
for /f %%a IN ('type services.txt') do call :chkservice %%a
goto :eof
:chkservice
@echo on
echo %a%
此代码显示 spooler
和 dhcp
仅有的。为什么不即插即用?我相信这两个问题是相关的,但不确定如何相关。
对此的任何帮助将不胜感激。
services.txt
contains:-
Plugplay
spooler
dhcp
I want to check the status of some services that are specified in file services.txt
. I am using for loop for this.
@echo off
for /f %%a IN ('type services.txt') do call :chkservice %%a
goto :eof
:chkservice
sc query %a%
Instead of getting the output for the three specified services, I am getting the output equivalent to three times the command sc query
(I guess).
For debugging I tried checking if the variable a
getting the values properly or not and tried this version of code:-
@echo off
for /f %%a IN ('type services.txt') do call :chkservice %%a
goto :eof
:chkservice
@echo on
echo %a%
This code display spooler
and dhcp
only. Why not plugplay? I Believe both the issues are related, but not sure how.
Any help on this would be highly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您调用函数,您的参数位于 %1,%2,...%n 中,而不是
%a%
中。for 循环的参数在该循环之外几乎是不可见的。
所以你的代码应该看起来像
If you call a function your parameters are in %1,%2,...%n not in
%a%
.The parameters of a for-loop are nearly invisble outside of that loop.
So your code should looks like