2014-02-06 94 views
3

当我通过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" 
+0

我改变%2%〜2即 SC打造 “ ”%1 binpath = “\〜%2 \” xxx.exe.config \“” ,但仍然得到错误: 文件是意外的此时 当我通过services.cmd 2“C:\ BIN \程序\文件夹\文件夹\文件夹” CORP \ ACCT密码,它的工作原理 貌似批处理文件不接受它作为参数 – prashanthkr08

+0

@ user1838411 - 尝试就像我在答案中所说的那样。另外,请执行foxidrive答案中显示的更改。 – dbenham

3

除了Dave的评论,你需要在这些行

if "%~1" == "" goto PARAMS 
if "%~2" == "" goto PARAMS 
if "%~3" == "" goto PARAMS 
if "%~4" == "" goto PARAMS 

但你需要检查所有四个参数(如果所有需要4个tildas )是这样的:

if "%~4" == "" goto PARAMS 
+0

非常感谢,工作。 – prashanthkr08