对 .bat 文件进行条件执行

发布于 2025-01-13 04:30:45 字数 536 浏览 0 评论 0原文

我被我的 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜还是长夜 2025-01-20 04:30:45

choice 命令 可用于 dosbox,并且可能是实现您想要的效果的唯一方法:

mount G .
G:
:start

rem --- descriptions ---

choice /c12 /s Your Choice is [1-2]: /n 
if errorlevel 2 goto two
if errorlevel 1 goto one
goto start 

:one
cd PRINCE~1
PRINCE.EXE
exit

:two
cd DOOMS
DOOM.EXE
exit

您可以使用 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:

mount G .
G:
:start

rem --- descriptions ---

choice /c12 /s Your Choice is [1-2]: /n 
if errorlevel 2 goto two
if errorlevel 1 goto one
goto start 

:one
cd PRINCE~1
PRINCE.EXE
exit

:two
cd DOOMS
DOOM.EXE
exit

You can check the the chosen option with if errorlevel but mind that errorlevel works like equal or bigger than.. and you should start with the bigger numbers first. You can check the result only with IF 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?)

じее 2025-01-20 04:30:45

我的一些调整:

@echo off

:start
G:

cls

echo  .:::::         .::::        .:: ::
echo  .::   .::    .::    .::   .::    .::
echo  .::    .:: .::        .::  .::
echo  .::    .:: .::        .::    .::
echo  .::    .:: .::        .::       .::
echo  .::   .::    .::     .::  .::    .::
echo  .:::::         .::::        .:: ::
echo.
echo.
echo     .::::          .:        .::       .:: .::::::::   .:: ::
echo   .:    .::       .: ::      .: .::   .::: .::       .::    .::
echo  .::             .:  .::     .:: .:: . .:: .::        .::
echo  .::            .::   .::    .::  .::  .:: .::::::      .::
echo  .::   .::::   .:::::: .::   .::   .:  .:: .::             .::
echo   .::    .:   .::       .::  .::       .:: .::       .::    .::
echo    .:::::    .::         .:: .::       .:: .::::::::   .:: ::
echo.
echo.

pause

cls

echo List of Games :
echo.
echo 1. Prince of Persia
echo 2. DOOMS
echo.

echo Select the Game [1-2]
choice /c12 /s "::" /n

cls

if errorlevel 2 goto two
if errorlevel 1 goto one

:one
cd PRINCE~1
PRINCE.EXE

:two
cd DOOMS
DOOM.EXE

rem --- without cd.. we cannot switch games bcz each time we enter the game folder ---
cd ..

goto start

Some of my tweaks :

@echo off

:start
G:

cls

echo  .:::::         .::::        .:: ::
echo  .::   .::    .::    .::   .::    .::
echo  .::    .:: .::        .::  .::
echo  .::    .:: .::        .::    .::
echo  .::    .:: .::        .::       .::
echo  .::   .::    .::     .::  .::    .::
echo  .:::::         .::::        .:: ::
echo.
echo.
echo     .::::          .:        .::       .:: .::::::::   .:: ::
echo   .:    .::       .: ::      .: .::   .::: .::       .::    .::
echo  .::             .:  .::     .:: .:: . .:: .::        .::
echo  .::            .::   .::    .::  .::  .:: .::::::      .::
echo  .::   .::::   .:::::: .::   .::   .:  .:: .::             .::
echo   .::    .:   .::       .::  .::       .:: .::       .::    .::
echo    .:::::    .::         .:: .::       .:: .::::::::   .:: ::
echo.
echo.

pause

cls

echo List of Games :
echo.
echo 1. Prince of Persia
echo 2. DOOMS
echo.

echo Select the Game [1-2]
choice /c12 /s "::" /n

cls

if errorlevel 2 goto two
if errorlevel 1 goto one

:one
cd PRINCE~1
PRINCE.EXE

:two
cd DOOMS
DOOM.EXE

rem --- without cd.. we cannot switch games bcz each time we enter the game folder ---
cd ..

goto start
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文