-1

在我的批处理脚本中使用此命令时,该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%"

我该如何防止这种情况?

4

2 回答 2

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%"
于 2019-07-15T11:07:04.837 回答
0

弄清楚了:

在我的原始脚本中,我将 nssm exe 作为变量:

%nssm% set %serviceName% AppDirectory "%maindir%"

不知何故,这使脚本感到困惑。

只需使用实际路径即可nssm.exe

.\nssm.exe set %serviceName% AppDirectory "%maindir%"
于 2019-07-15T09:25:08.640 回答