前言:自从我创建了一个批处理文件以来,已经有一段时间了,这是我第一次使用这个网站,所以如果 我忽视或忘记做某事只是指出来,我会解决它。
今天我决定回到一些dos游戏,我想制作一个批处理文件,允许我追加三个 文本行,本质上是你通常手动编写的mount-> c: - > .exe行到[autoexec]部分 dosbox.conf。
经过一天的修修补补后,我终于让批处理文件与几款游戏一起工作了,warcraft2 / DungeonMaster / LandsofLore, 我现在唯一的问题是代码适用于上面提到的三个,但其他没有 甚至附加到dosbox.conf。
('调试'之后,使用了warcraft1) 我在'set / p input'之后输入了pause命令,在war1标签的war语句的开头和结尾也放了war1的if语句。触发的唯一暂停是'set / p input',所以代码要么忽略If语句,要么我不知道我在做什么。
关于我做错的任何指示都将不胜感激。 TL:DR代码适用于warcraft2(输入w),Land of Lore(输入l),dungeon master(输入d)其他输入似乎要么在输入后立即退出要么在取消之前到达IF语句/ s
@echo off
REM ask is currently not used
:ask
REM asks for input
echo Which game would you like to play?
echo ___________________________________________________________________________________________
echo [w]arcraft 2 - w[a]rcraft1 - [c]ivilization - d[u]ne 2 - [d]ungeon master
echo [l]ands of lore - [o]regontrail - [s]im ant - Wol[f]3D
echo -------------------------------------------------------------------------------------------
REM input variable
setlocal
SET /P INPUT=[]
REM check user input then go to selected game
IF /I "%INPUT%"=="w" (
goto war2
)
IF /I "%INPUT%"=="d" (
goto dungeon
)
IF /I "%INPUT%"=="l" (
goto land
)
IF /I "%INPUT%"=="a"(
goto war1
)
IF /I "%INPUT%"=="c"(
goto civ
)
IF /I "%INPUT%"=="u"(
goto dune2
)
IF /I "%INPUT%"=="o"(
goto trail
)
IF /I "%INPUT%"=="s"(
goto ant
)
IF /I "%INPUT%"=="f"(
goto wolf
)
REM appends text to the end of dosbox.conf,after the [autoexec]
REM then starts dosbox and ends the file.
:war1
ECHO mount -u c>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
ECHO mount c f:\DOSGames\war1\ -label warcraft1>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
ECHO c:>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
ECHO WAR>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
start F:\Programs\DOSBoxPortable\DOSBoxPortable.EXE
goto:EOF
:civ
ECHO mount -u c>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
ECHO mount c f:\DOSGames\civ\ -label Civ>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
ECHO c:>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
ECHO CIV>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
start F:\Programs\DOSBoxPortable\DOSBoxPortable.EXE
goto:EOF
:dune2
ECHO mount -u c>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
ECHO mount c f:\DOSGames\dun2\ -label Dune 2>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
ECHO c:>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
ECHO DUNE2>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
start F:\Programs\DOSBoxPortable\DOSBoxPortable.EXE
goto:EOF
:trail
ECHO mount -u c>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
ECHO mount c f:\DOSGames\oregontrail\ -label Oregon Trail>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
ECHO c:>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
ECHO OREGON>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
start F:\Programs\DOSBoxPortable\DOSBoxPortable.EXE
goto:EOF
:ant
ECHO mount -u c>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
ECHO mount c f:\DOSGames\simant\ -label Sim Ant>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
ECHO c:>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
ECHO SIMANT>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
start F:\Programs\DOSBoxPortable\DOSBoxPortable.EXE
goto:EOF
:wolf
ECHO mount -u c>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
ECHO mount c f:\DOSGames\WOLF3D\ -label Oregon Trail>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
ECHO c:>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
ECHO WOLFD3D>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
start F:\Programs\DOSBoxPortable\DOSBoxPortable.EXE
goto:EOF
:war2
ECHO mount -u c>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
ECHO mount c f:\DOSGames\war2\war2\ -label warcraft2>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
ECHO c:>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
ECHO war2>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
start F:\Programs\DOSBoxPortable\DOSBoxPortable.EXE
goto:EOF
:dungeon
ECHO mount -u c>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
ECHO mount c f:\DOSGames\DungeonMaster\ -t cdrom -label DungeonMaster>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
ECHO c:>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
ECHO dm>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
start F:\Programs\DOSBoxPortable\DOSBoxPortable.EXE
goto:EOF
:land
ECHO mount -u c>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
ECHO mount c f:\DOSGames\LoL\ -label lands>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
ECHO c:>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
ECHO lands>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
start F:\Programs\DOSBoxPortable\DOSBoxPortable.EXE
答案 0 :(得分:1)
您从命令提示符运行脚本而不是双击它,您会看到您收到“命令的语法不正确”错误。
这是因为除了“魔兽争霸2”,“地牢大师”和“传说之地”之外,您在每个(
语句中都缺少if
之前的空格。
IF /I "%INPUT%"=="w" (
goto war2
)
IF /I "%INPUT%"=="d" (
goto dungeon
)
IF /I "%INPUT%"=="l" (
goto land
)
IF /I "%INPUT%"=="a" (
goto war1
)
IF /I "%INPUT%"=="c" (
goto civ
)
IF /I "%INPUT%"=="u" (
goto dune2
)
IF /I "%INPUT%"=="o" (
goto trail
)
IF /I "%INPUT%"=="s" (
goto ant
)
IF /I "%INPUT%"=="f" (
goto wolf
)
您也可以通过将goto
放在与if
s相同的行而没有括号的情况下避免这种情况。
IF /I "%INPUT%"=="w" goto war2
IF /I "%INPUT%"=="d" goto dungeon
IF /I "%INPUT%"=="l" goto land
IF /I "%INPUT%"=="a" goto war1
IF /I "%INPUT%"=="c" goto civ
IF /I "%INPUT%"=="u" goto dune2
IF /I "%INPUT%"=="o" goto trail
IF /I "%INPUT%"=="s" goto ant
IF /I "%INPUT%"=="f" goto wolf
答案 1 :(得分:1)
输入值尾随双引号与不起作用的行中的左括号之间缺少空格。
但是,我建议进行此更改,以便更轻松地管理代码。
为重复的条目使用变量,然后循环返回Ask和Quit选项。
@echo off
setlocal
:: ask is currently not used
:ask
:: asks for input
cls
echo Which game would you like to play?
echo ___________________________________________________________________________________________
echo [w]arcraft 2 - w[a]rcraft1 - [c]ivilization - d[u]ne 2 - [d]ungeon master
echo [l]ands of lore - [o]regontrail - [s]im ant - Wol[f]3D - [Q]uit
echo -------------------------------------------------------------------------------------------
:: input variable
SET /P INPUT=[]
IF /I "%INPUT%"=="q" then Exit
set DosBoxConf="F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"
set MountDrive=mount -u c
set MyDrive=C:
:: check user input then go to selected game
IF /I "%INPUT%"=="w" (
set MountCmd=mount c f:\DOSGames\war2\war2\ -label warcraft2
set RunCmd=WAR2
goto RunDosBox
)
IF /I "%INPUT%"=="d" (
set MountCmd=mount c f:\DOSGames\DungeonMaster\ -t cdrom -label DungeonMaster
set RunCmd=DM
goto RunDosBox
)
IF /I "%INPUT%"=="l" ( )
set MountCmd=mount c f:\DOSGames\LoL\ -label lands
set RunCmd=lands
goto RunDosBox
)
IF /I "%INPUT%"=="a" (
set MountCmd=mount c f:\DOSGames\war1\ -label warcraft1
set RunCmd=WAR
goto RunDosBox
)
IF /I "%INPUT%"=="c" (
set MountCmd=mount c f:\DOSGames\civ\ -label Civ
set RunCmd=CIV
goto RunDosBox
)
IF /I "%INPUT%"=="u" (
set MountCmd=mount c f:\DOSGames\dun2\ -label Dune 2
set RunCmd=DUNE2
goto RunDosBox
)
IF /I "%INPUT%"=="o" (
set MountCmd=mount c f:\DOSGames\oregontrail\ -label Oregon Trail
set RunCmd=OREGON
goto RunDosBox
)
IF /I "%INPUT%"=="s" (
set MountCmd=mount c f:\DOSGames\simant\ -label Sim Ant
set RunCmd=SIMANT
goto RunDosBox
)
IF /I "%INPUT%"=="f" (
set MountCmd=mount c f:\DOSGames\WOLF3D\ -label Wolf 3D
set RunCmd=WOLFD3D
goto RunDosBox
)
:: back to ask if input didn't match a choice
goto ask
:RunDosBox
:: build the config and run DosBox
ECHO %MountDrive%>>%DosBoxConf%
ECHO %MountCmd%>>%DosBoxConf%
ECHO %MyDrive%>>%DosBoxConf%
ECHO %RunCmd%>>%DosBoxConf%
start F:\Programs\DOSBoxPortable\DOSBoxPortable.EXE
另请注意,代码中的这一行有一个错误的Oregon Trail标记,但该部分适用于Wolf3D。
ECHO mount c f:\DOSGames\WOLF3D\ -label Oregon Trail>>"F:\Programs\DOSBoxPortable\Data\settings\dosbox.conf"