Batch Error: “( was not expected at this time”
Batch Error: “( was not expected at this time”
我正在做一个批处理文件来编译一些 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
此外,是否可以查看错误导致问题的确切行?
我没有测试你的代码,但乍一看你似乎有两个语法错误。
第一个错误是关于 GoTo
语句,它只接受一个参数,即 label/sub-routine 名称,但您试图传递多个参数。您可以使用 Call
或 set/save 参数代替 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" "
我正在做一个批处理文件来编译一些 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
此外,是否可以查看错误导致问题的确切行?
我没有测试你的代码,但乍一看你似乎有两个语法错误。
第一个错误是关于 GoTo
语句,它只接受一个参数,即 label/sub-routine 名称,但您试图传递多个参数。您可以使用 Call
或 set/save 参数代替 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" "