当我将path
作为我的第二个参数传递时,我收到以下错误。看起来问题在于空间。
Files was unexpected at this time
我正在使用以下参数执行批处理文件
services.cmd 2 "C:\Program Files (x86)\folder\Folder\folder\Bin" corp\acct password
CODE:
@echo off
if "%1" == "" goto PARAMS
if "%2" == "" goto PARAMS
if "%3" == "" goto PARAMS
if "%4" == "" goto PARAMS
sc create "<service name>"%1 binpath= "\%2\xxx.exe\" \"xxx.exe.config\""
rem sc config "<service name>"%1 displayname= "<display name>"%1 obj= %3 password= %4 start= auto description= "Runs the service."
goto END
:PARAMS
echo Usage CreateServices.cmd binfoldername binfolderpath username password
:END
答案 0 :(得分:4)
您无法在带引号的字符串中转义引号。使用%~2
删除参数中不需要的引号。
尝试以下方法:
sc create "<service name>%~1" binpath= "%~2\xxx.exe" "xxx.exe.config"
答案 1 :(得分:3)
除了Dave的评论之外,你还需要这些行中的tildas
if "%~1" == "" goto PARAMS
if "%~2" == "" goto PARAMS
if "%~3" == "" goto PARAMS
if "%~4" == "" goto PARAMS
但是您需要检查所有四个参数(如果需要全部4个参数),请执行以下操作:
if "%~4" == "" goto PARAMS