为什么IF / ELSE命令在我的批处理代码中不起作用?

时间:2015-01-04 08:44:30

标签: batch-file

尝试让程序运行多人合作社,但我的批处理脚本不起作用,我想我已经大量完成了。试着让朋友帮忙,最后得到了这个,而且根本没有工作,我已经失去了所有的进步。有人能告诉我这里有什么问题和/或纠正它吗?

:hostmpcoop
set /p files="(Optional) Enter stuff to run spaced by -file : "
set /p playercount="Enter number of desired players: "
if "%files%"=="" (
    echo No files entered.
    if not "%playercount%" == "" (
        echo Running vanilla MP
        thing.exe -host %playercount% 
    )else(
        echo You need to specify a playercount!
        goto hostmpcoop
    )
)
if not "%files%"=="" (
    if not "%playercount%"=="" (
        thing.exe -host %playercount% -file %files%
    )else(
        echo You need to specify a playercount!
        goto hostmpcoop
    )
)
if "%files%"==""(
    if "%playercount%"=="" (
        echo "Enter a player count!"
        goto hostmpcoop
    )
)
goto home

1 个答案:

答案 0 :(得分:1)

你需要在括号周围使用空格,如果使用的话:

:hostmpcoop
set /p files="(Optional) Enter stuff to run spaced by -file : "
set /p playercount="Enter number of desired players: "
if "%files%"=="" (
    echo No files entered.
    if not "%playercount%" == "" (
        echo Running vanilla MP
        thing.exe -host %playercount% 
    ) else (
        echo You need to specify a playercount!
        goto hostmpcoop
    )
)
if not "%files%"=="" (
    if not "%playercount%"=="" (
        thing.exe -host %playercount% -file %files%
    ) else (
        echo You need to specify a playercount!
        goto hostmpcoop
    )
)
if "%files%"=="" (
    if "%playercount%"=="" (
        echo "Enter a player count!"
        goto hostmpcoop
    )
)

转到家