batch-filedosdosbox

How to make a prompt to open different things with a batch file in DOSBox?


I've been making batch file shortcuts to my dos games in dosbox, and I want to make a batch file for doom 2 that asks you if you want to open doom 2, or open the setup file by typing either 1 or 2. How would I do that?

I tried asking ChatGPT for the batch file code to do that (See below), but it just opens doom 2 regardless of input. I have barely any experience in batch file coding, so I have no idea what I'm doing wrong here.

@echo off
echo Select a file to open:
echo 1. DOOM2.EXE
echo 2. SETUP.EXE

set /p choice=Enter your choice (1-2): 
pause

if "%choice%"=="1" (
    DOOM2.bat
) else if "%choice%"=="2" (
    SETDOM2.bat
pause
) else (
    echo Invalid choice. Exiting...
    pause
    exit /b
)

Solution

  • Display a menu with echo and wait for the user's response via the choice command that sets the errorlevel. It is important that these errorlevels get interrogated from high to low:

    @echo off
    echo Make selection (press # and ENTER)
    echo ==================================
    echo 1. DOOM2.EXE
    echo 2. SETUP.EXE
    echo 3. EXIT MENU
    choice /c123
    if errorlevel 3 goto exit
    if errorlevel 2 goto setup
    if errorlevel 1 goto play
    
    :play
    call DOOM2.bat
    goto exit
    
    :setup
    call SETDOM2.bat
    
    :exit
    echo .
    

    This was tested in DOSBox 0.74 just now.