批处理脚本函数调用工作不正常

问题描述

我编写了简单的批处理脚本来根据参数执行两个单独的功能。但是每当我使用“服务测试”参数在 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 (将#修改为@)