2

Win32で実行されないゲーム用のレガシーDOSシステム用のバッチファイルを作成しました。コードはXPx86で正常に機能しますが、98SEまたはDOSで実行すると、最初のプロンプトの後に構文エラーが発生します。gotoのおかげで、ファイルはループに陥ります。これを修正するにはどうすればよいですか?

ソースコード:

@echo off
:PROMPT
cls
echo.
echo  Welcome to the Game Selection Wizard!
echo  --------------------------------------
echo.
echo  Please Select a Game: 
echo.
echo  1. Game1
echo  2. Game2
echo  3. Return To MS-DOS
echo.
set /p GAME= Your Current Selection: 
if %game%==1 goto Game1
if %game%==1. goto Game1
if %game%==2 goto Game2
if %game%==2. goto Game2
if %game%==3 goto QUIT
if %game%==3. goto QUIT
goto INVALID
:INVALID
cls
echo.
echo  * * * * * * * * * * * * * * * * * * * * * * * * * * *
echo  *                                                   *
echo  * ERROR:                                            *
echo  * ------                                            *
echo  * The choice you selected is wrong. Try Again!      *
echo  *                                                   *
echo  * * * * * * * * * * * * * * * * * * * * * * * * * * *
echo.
echo  Welcome to the Game Selection Wizard!
echo  -------------------------------------
echo.
echo  Please Select a Game: 
echo.
echo  1. Game1
echo  2. Game2
echo  3. Return To MS-DOS
echo.
set /p gameerror= Your Current Selection: 
if %gameerror%==1 goto Game1
if %gameerror%==1. goto Game1
if %gameerror%==2 goto Game2
if %gameerror%==2. goto Game2
if %gameerror%==3 goto QUIT
if %gameerror%==3. goto QUIT
cls
goto INVALID
:Game1
cls
call A:\GAMES\Game1.exe
goto PROMPT
:Game2
cls
call A:\GAMES\Game2.exe
goto PROMPT
:QUIT
cls
echo.
echo  Are you sure you want to return to MS-DOS?
echo.
set /p quit= Confirmation: 
if %quit%==y goto DIE
if %quit%==Y goto DIE
if %quit%==yes goto DIE
if %quit%==Yes goto DIE
if %quit%==YES goto DIE
if %quit%==n goto PROMPT
if %quit%==N goto PROMPT
if %quit%==no goto PROMPT
if %quit%==No goto PROMPT
if %quit%==NO goto PROMPT
goto QUITERROR
:QUITERROR
cls
echo  * * * * * * * * * * * * * * * * * * * * * * * * * * *
echo  *                                                   *
echo  * ERROR:                                            *
echo  * ------                                            *
echo  * The choice you selected is wrong. Try Again!      *
echo  *                                                   *
echo  * * * * * * * * * * * * * * * * * * * * * * * * * * *
echo.
echo  Are you sure you want to return to MS-DOS?
echo.
set /p quiterror= Confirmation: 
if %quiterror%==y goto DIE
if %quiterror%==Y goto DIE
if %quiterror%==yes goto DIE
if %quiterror%==Yes goto DIE
if %quiterror%==YES goto DIE
if %quiterror%==n goto PROMPT
if %quiterror%==N goto PROMPT
if %quiterror%==no goto PROMPT
if %quiterror%==No goto PROMPT
if %quiterror%==NO goto PROMPT
goto QUITERROR
:DIE
cls
echo.
echo  Returning to MS-DOS...
4

2 に答える 2

4

AFAIR-そしてそれはずっと前のことです-SET/PはNTのみです。

于 2013-03-08T05:21:43.080 に答える
1

最初にVERを使用して、出力をFIND(findstrではない)にパイプし、「重要な文字列」を探して、OSを検出します。これは一度だけ行う必要があります-したがって、@ECHO OFF

set running=NT
ver|find "1998" >nul
if not errorlevel 1 set running=DOS

「1998」は、Win98のVERにのみ表示される重要な文字列です。他に探すべき値は「2222」(W98SE)と「3000」(WinME)です。したがって、検出する必要のある文字列に対してラインペアを繰り返すだけです。

入力を受け入れる場合は、NTの場合はSET / P、DOSの場合はCHOICEを使用する必要があります

if%running%= NT set / p ....&goto:ntxxx :: else running DOS choice .. ..

ここで、ラベルNTXXXはNT入力の処理です(たとえば、「2」または「2」を許可しているように見えます)。

CHOICEコマンドはキーストロークに反応し、使用されたキーストロークに応じてERRORLEVELを設定します。CHOICE/?構文が表示されます。IF ERRORLEVEL xxつまり、"If errorlevel is xx OR GREATER"逆の順序で行われた選択を処理する必要があります(最後の位置=最初に最高のERRORLEVEL)

(XPより前のシステムに簡単にアクセスできなくなったため、上記はすべてメモリからのものです)

興味深いことに、CHOICEはVistaで再登場しました...

于 2013-03-09T16:17:16.533 に答える