windows - 批处理脚本函数调用工作不正常
问题描述
我编写了简单的批处理脚本来根据参数执行两个单独的功能。但是,每当我在 cmd 中使用“service test”参数运行脚本时,它都会调用 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
服务重启日志
"Calling RestartService function"
"Restarting the service"
日志文件显示没有调用 ProcessKill 函数,但 cmd 中的输出显示它正在被调用,无法理解哪个是正确的。请注意。
解决方案
推荐阅读
- opencv - 如何使用 OpenCV 检测图像中颜色均匀的矩形?
- php - 有没有办法从单个页面导出 CSS 和 HTML 代码?
- docker - Docker 重复层被推送
- sql - 如何将一个表中的多个列连接到另一个查找表?
- angular - 如何在 Ionic 4 firebase PWA 应用程序中将 promise 转换为 observable
- mysql - bash shell mysql 命令从命令行运行,但不在脚本内部
- c# - 如何显示列表的内容
在 ComboBox 中使用 Caliburn.micro? - machine-learning - 使用 PyTorch 与模型的正向传递并行执行另一个模型
- javascript - Material-UI v1 Drawer 组件在 iOS 13 beta 版本中不起作用
- c# - 在 TabControl 内切换时显示设置为 Visible=false 的项目