如何解决批处理脚本函数调用工作不正常
我编写了简单的批处理脚本来根据参数执行两个单独的功能。但是每当我使用“服务测试”参数在 cmd 中运行脚本时,它都会调用 ProcessKill 函数。你能帮我了解这里发生的事情吗。
@Echo Off
set jobName=%1
set pidORServiceName=%2
echo %jobName%
echo %pidORServiceName%
cd "%~dp0"
>ServiceRestart.log 2>&1 (
if %jobName%==pkill (
echo "Calling ProcessKill function"
call:ProcessKill
)
if %jobName%==service (
echo "Calling RestartService function"
call:RestartService
)
)
:ProcessKill
echo "killing the process" + %pidORServiceName%
taskkill /f /pid %pidORServiceName%
if %ERRORLEVEL% NEQ 0 (
echo "Some error occurred with errorlevel" + %ERRORLEVEL%
) else (
echo "killed the process"
)
goto:eof
:RestartService
echo "Restarting the service"
goto:eof
cmd运行输出:
ServicesRestart.bat service test
service
test
"killing the process" + test
ERROR: The process "test" not found.
"Some error occurred with errorlevel" + 128
ServiceRestart.log
"Calling RestartService function"
"Restarting the service"
日志文件显示未调用 ProcessKill 函数,但 cmd 中的输出显示它正在被调用,无法理解哪个正确显示图片。请多多指教。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。