Batch file 批次错误:“;(当时没有预料到”;
我正在做一个批处理文件来编译一些dll,我遇到了一个简单但无法检测到的错误 这很简单,我不明白为什么CMD会给我这个错误,我的代码是:Batch file 批次错误:“;(当时没有预料到”;,batch-file,cmd,unexpected-token,Batch File,Cmd,Unexpected Token,我正在做一个批处理文件来编译一些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
@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
也许,我遗漏了一些东西,但我看不到我的代码中有任何失败,可能是因为我缺乏经验,无论如何,请帮助我解决它,因为我已经附上了所有可能会导致麻烦的条件和一切
所有来源都可以在这里看到:
另外,是否可以看到错误导致问题的确切位置?我没有测试您的代码,但乍一看您似乎有两个语法错误 第一个错误是关于
GoTo
语句,它只接受一个参数,即标签/子程序名称,但您试图传递多个参数。您可以使用Call
,而不是GoTo
,或者将参数设置/保存到变量中,然后调用GoTo
,只传递标签名称并最终读取变量中的参数值
第二个错误是,您没有用引号括住CMD参数
根据需要调用CMD的正确语法如下:
CMD.exe /C "argument"
在这种情况下,您传入一个参数,该参数表示接受包含空格的其他参数的命令,那么这些参数也必须包含在内,如下所示:
CMD.exe /C " script.bat "C:\path with spaces" "
CMD.exe /C " "compile.bat" "%~1" "%~2" "
或者:
CMD.exe /C " Start /W "" "script.bat" "C:\path with spaces" "
所以试着这样做:
CMD.exe /C " script.bat "C:\path with spaces" "
CMD.exe /C " "compile.bat" "%~1" "%~2" "
是的,您很可能看到错误所在。请删除
@echo off
,打开cmd提示符并从cmd提示符执行批处理文件,而不是用鼠标双击它。您不能像这样使用GOTO
:GOTO:callcompile“%cpath%”%order%”
。您没有将任何内容传递给子例程。也必须使用延迟扩展引用您的cpath变量。脚本返回给我的操作是您建议的@Squashman:而不是goto:callcompile“%cpath%”“%order%”尝试call:callcompile“%%cpath%%”“%order%”
。同样的情况也会发生@Compo谢谢。