您的问题是检索AppParameters时的 unicode 输出。您可以将其处理为
nssm get MyWindowsService AppParameters > tempFile
for /f "delims=" %%a in ('
^< tempFile find /v ""
') do (
nssm.exe set MyWindowsService AppParameters "%%a --baseUrl helloworld.txt"
)
或者
nssm get MyWindowsService AppParameters > tempFile
for /f "delims=" %%a in ('
more tempFile
') do (
nssm.exe set MyWindowsService AppParameters "%%a --baseUrl helloworld.txt"
)
或者,没有临时文件
for /f "delims=" %%a in ('
nssm get MyWindowsService AppParameters ^| sort
') do (
nssm.exe set MyWindowsService AppParameters "%%a --baseUrl helloworld.txt"
)
编辑了包含如何处理引号的示例代码。
@echo off
setlocal enableextensions disabledelayedexpansion
set "svc=MyWindowsService"
nssm install "%svc%" "c:\windows\system32\cmd.exe"
nssm set "%svc%" Start SERVICE_DEMAND_START
nssm set "%svc%" AppParameters "--client-version ""6.1.0"""
echo ---------------------------------------------------------------
nssm get "%svc%" AppParameters
echo ---------------------------------------------------------------
for /f "delims=" %%a in ('
nssm get "%svc%" AppParameters ^| sort
') do (
set "appParams=%%a"
setlocal enabledelayedexpansion
nssm.exe set "%svc%" AppParameters "!appParams:"=""!" "--baseUrl=""C:\ProgramData\\"""
endlocal
)
echo ---------------------------------------------------------------
nssm get "%svc%" AppParameters
echo ---------------------------------------------------------------
nssm remove "%svc%" confirm