2014-02-06 124 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