在批处理脚本中使用此命令时,set
命令将被解释为默认的Windows批处理“设置环境命令”:
@echo off
echo "Always run this script as Administrator. If you don't the service will be installed but not correctly configured!"
set serviceName=MyApp
set serviceLabel=MyApp
set serviceExe=MyApp.exe
set maindir=C:\\Users\\MyUser\\Desktop\\MyApp\\
set nssm=%maindir%\\lib\\nssm-2.24\\win64\\nssm.exe
%nssm% install %serviceName% "%maindir%\\%serviceExe%"
如何防止这种情况?
答案 0 :(得分:1)
基于我的评论的示例:
@Echo Off
Set "serviceName=MyApp"
Set "serviceExe=MyApp.exe"
Set "maindir=C:\\Users\\MyUser\\Desktop\\MyApp"
Set "nssm=%maindir%\\lib\\nssm-2.24\\win64\\nssm.exe"
"%nssm:\\=\%" install %serviceName% "%maindir%\\%serviceExe%"
答案 1 :(得分:0)
想通了:
在我的原始脚本中,我将nssm exe作为变量:
%nssm% set %serviceName% AppDirectory "%maindir%"
以某种方式使脚本混乱。
只需使用到nssm.exe
的实际路径即可,
.\nssm.exe set %serviceName% AppDirectory "%maindir%"