对 .bat 文件进行条件执行
我被我的 .bat 困住了,它无法正确执行,如果有任何错误,请报告它
文件名 - games.bat
@echo off
G:
:start
cls
echo DOS Games
echo 1. DOOMS
echo 2. Prince of Persia
set /p choice=Your Choice is
pause
if %choice% == 1 goto 1
if %choice% == 2 goto 2
if %choice% == %choice% goto start
:1
cd PRINCE~1
PRINCE.EXE
exit
:2
cd DOOMS
DOOM.EXE
exit
我只想通过选择游戏编号来运行游戏
我在 DOSBOX 中运行 .bat,这可能不是与 Windows Bat 语法兼容
另外,任何其他建议对我来说都可以,
我习惯于为许多游戏一次又一次地编写新的配置文件和 shell 脚本,所以我决定编写一个可以在 DOSBOX 上运行并通过以下方式加载游戏的 .bat 代码:一
I'm stuck with my .bat that doesn't execute correctly if any mistakes please report it
File name - games.bat
@echo off
G:
:start
cls
echo DOS Games
echo 1. DOOMS
echo 2. Prince of Persia
set /p choice=Your Choice is
pause
if %choice% == 1 goto 1
if %choice% == 2 goto 2
if %choice% == %choice% goto start
:1
cd PRINCE~1
PRINCE.EXE
exit
:2
cd DOOMS
DOOM.EXE
exit
I just want to run the games by selecting their numbers
I'm running the .bat in DOSBOX which may not be compatible with windows bat syntax
Also any other suggestions are ok to me
I'm tierd of writing new config files and shell scripts again and again for many games so I decided to write a .bat code which can run on DOSBOX and load games one by one
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
choice 命令 可用于 dosbox,并且可能是实现您想要的效果的唯一方法:
您可以使用
if errorlevel
检查所选选项,但请注意,errorlevel 的工作方式类似于等于或大于..
,并且您应该首先从较大的数字开始。您只能使用IF ERRORLEVEL
检查结果,因为%ERRORLEVEL%
变量不可访问,并且不能在 dosbox 下使用三字母比较运算符。我注意到的另一件事是没有设备映射。要访问 dosbox 下的文件,您需要首先将某个目录挂载为驱动器。这里我挂载了 G: 作为当前目录。(或者可能它挂载在conf文件中?)
The choice command is available for dosbox and probably the only way to achieve what you want:
You can check the the chosen option with
if errorlevel
but mind that errorlevel works likeequal or bigger than..
and you should start with the bigger numbers first. You can check the result only withIF ERRORLEVEL
as%ERRORLEVEL%
variable is not accessible and you cannot use the three letter comparison operators under dosbox.The other thing I've noticed is that there's no mapping of a device. To have access to your files under dosbox you need to mount a certain directory as a drive first. Here I've mounted G: as the current directory.(or may be it is mounted in the conf file?)
我的一些调整:
Some of my tweaks :