2017-02-13 54 views
1

我做一個批處理文件來編譯一些DLL,而且幸虧我被困在一個簡單的,但檢測不到錯誤...批量錯誤:「(預計不會在這個時候」

那麼,這是簡單的我想不通爲什麼CMD是給我這個錯誤,有我的代碼:

@echo off 
::Call this in case your broke you dll and you cannot start Unity for example 

:str 
cls 
goto :main 

:main 
echo Hello, well, if you're opening this is because you have done something wrong and you cannot start Unity... 
echo. 
set /p opt="Do you want to read your path from the 'path.txt' file or do you want to specify? [Y/N] " 
echo. 
echo Also, this is optional but you can try to establish an order for the compilation. 
echo. 
echo 1.- Build the API 
echo 2.- Build the RAW Scripts 
echo 3.- Build the Editor API 
echo. 
set /p order="Type, for example: [2 1 3], to compile in this order, or the way you want: " 

if /i "%opt%" == "Y" (
    for /f "delims=" %%f in ("project_path.txt") do (
     if "%%f" NEQ "" (
      call :callcompile "%%f" "%order%" 
     ) 
    ) 
) else (
    if /i "%opt%" == "N" (
     echo. 
     set /p cpath="Path: " 
     goto :callcompile "%cpath%" "%order%" 
    ) else (
     goto :str 
    ) 
) 
goto :EOF 

:callcompile 
cmd /c compile.bat "%~1" "%~2" 
pause 

也許,我失去了一些東西,但我看不到任何失敗在我的代碼,也許是因爲我的經驗不足,無論如何,幫助我解決它,因爲我已經附上了所有的條件和一切可能導致麻煩而不幸的事情。所有的來源可以在這裏看到:https://github.com/Lerp2Dev/Lerp2API/blob/master/Compile/emergency_case.bat

此外,有無論如何看到錯誤導致問題的確切線?

+1

是的,您可能很有可能看到錯誤在哪裏。刪除'@echo off',打開一個cmd提示符並從cmd提示執行你的批處理文件,而不是用鼠標雙擊它。 – Squashman

+0

你不能像這樣使用'GOTO':'goto:callcompile「%cpath%」「%order%」'。你沒有把任何東西傳遞給你的子程序。你的cpath變量也必須通過延遲擴展來引用。 – Squashman

+0

這個腳本返回給我做什麼你做什麼建議@Squashman:http://pastebin.com/DkB2RsZv – z3nth10n

回答

1

我沒有測試你的代碼,但乍一看似乎你有兩個語法錯誤。

第一個錯誤是關於GoTo語句,它只接受一個參數,即標籤/子例程名稱,但您嘗試傳遞多個參數。您可以使用Call來代替GoTo,或者將參數設置/保存到變量中,然後調用GoTo只傳遞標籤名稱,最後從變量中讀取參數值。

第二個錯誤,是因爲你沒有用引號括住CMD參數。

正確的語法來調用CMD,只要你想,會是這樣:

CMD.exe /C "argument" 

,其中在這種情況下,你在那個表示需要包含空格的附加參數的命令參數傳遞,然後他們也必須被封閉,就像這樣:

CMD.exe /C " script.bat "C:\path with spaces" " 

或者也:

CMD.exe /C " Start /W "" "script.bat" "C:\path with spaces" " 

因此請試試這樣:

CMD.exe /C " "compile.bat" "%~1" "%~2" " 
+0

'cmd/C script.bat「C:\帶空格的路徑」應該工作得很好...... – aschipfl