批量命令输入菜单

时间:2013-05-21 11:35:40

标签: batch-file batch-processing

我有一个问题。可以使批处理菜单同时接受多个命令吗?

示例:(我的代码)

@ECHO OFF

set tries=6
:top
cls
set /a tries=%tries% -1
if %tries%==0 (
goto penalty
)
Echo You have %tries% attempts left.
Echo Please enter your password to proceed
set /p password=
if %password%==Parola ta (
echo Welcome Your Name
ping localhost -n 5 >nul
cls
Echo CONNECTED!



C:
CD\
CLS

:MENU
CLS

ECHO  ============= MENU NAME =============
ECHO -------------------------------------
ECHO 1.  System Information TXT file
ECHO 2.  Selection 2
ECHO 3.  Selection 3
ECHO 4.  Selection 4
ECHO 5.  Selection 5
ECHO 6.  Selection 6
ECHO 7.  Selection 7
ECHO -------------------------------------
ECHO 8.  Selection 8
ECHO -------------------------------------
ECHO 9.  Selection 9
ECHO -------------------------------------
ECHO ==========PRESS 'Q' TO QUIT==========
ECHO.

SET INPUT=
SET /P INPUT=Please select a number:

IF /I '%INPUT%'=='1' GOTO Selection1
IF /I '%INPUT%'=='2' GOTO Selection2
IF /I '%INPUT%'=='3' GOTO Selection3
IF /I '%INPUT%'=='4' GOTO Selection4
IF /I '%INPUT%'=='5' GOTO Selection5
IF /I '%INPUT%'=='6' GOTO Selection6
IF /I '%INPUT%'=='7' GOTO Selection7
IF /I '%INPUT%'=='8' GOTO Selection8
IF /I '%INPUT%'=='9' GOTO Selection9
IF /I '%INPUT%'=='Q' GOTO Quit

CLS

ECHO ============INVALID INPUT============
ECHO -------------------------------------
ECHO Please select a number from the Main
echo Menu [1-9] or select 'Q' to quit.
ECHO -------------------------------------
ECHO ======PRESS ANY KEY TO CONTINUE======

PAUSE > NUL
GOTO MENU

:Selection1

systeminfo.exe>systeminfo.txt

ECHO ============INVALID INPUT============
ECHO -------------------------------------
ECHO Please select a number from the Main
echo Menu [1-9] or select 'Q' to quit.
ECHO -------------------------------------
ECHO ======PRESS ANY KEY TO CONTINUE======

PAUSE > NUL
GOTO MENU


:Selection2

Call cleanup.bat

:Selection3

and in here too...

:Selection4

and so on

:Selection5

and so on

:Selection6

and so on

:Selection7

and so on

:Selection8

and so on

:Selection9

and so on

:Quit
CLS

ECHO ==============THANKYOU===============
ECHO -------------------------------------
ECHO ======PRESS ANY KEY TO CONTINUE======

PAUSE>NUL
EXIT

pause
cls
) else (
goto top
)
goto top

如何让程序接受多于1个命令? 例如1,3,5同时执行?

或另一个问题,如何将.exe撤回到.bat? 有这样的程序吗?

3 个答案:

答案 0 :(得分:3)

建议:从call制作goto并将命令与&连接起来:

IF /I '%INPUT%'=='1' GOTO:Selection1
IF /I '%INPUT%'=='2' CALL:Selection2&CALL:Selection2&CALL:Selection4
IF /I '%INPUT%'=='3' CALL:Selection3&CALL:Selection3
IF /I '%INPUT%'=='4' CALL:Selection4&CALL:Selection4
IF /I '%INPUT%'=='5' CALL:Selection5
IF /I '%INPUT%'=='6' CALL:Selection6
IF /I '%INPUT%'=='7' CALL:Selection7
IF /I '%INPUT%'=='8' CALL:Selection8
IF /I '%INPUT%'=='9' CALL:Selection9
IF /I '%INPUT%'=='Q' GOTO:Quit

要完成这项工作,您必须在跳转标签后添加goto:eofeof =文件结尾),例如:

:Selection2
Call cleanup.bat
goto:eof

:Selection3
and in here too...
goto:eof

:Selection4
and so on
goto:eof

:Selection5
and so on
goto:eof
...
..
.

goto:eof将控制权返回给主程序。

答案 1 :(得分:2)

这是你在找什么?

文件Menu.cmd

@echo off

    setlocal

    set quit=false
    set /p InputChoices=Enter Choice(s) (A,B,C) 
    echo %InputChoices%
    call :executeChoices %InputChoices%

    endlocal

goto :eof

:executeChoices 

    if [%1]==[] goto :eof

    call :Step%1
    shift
    goto :executeChoices    

goto :eof

:StepA
    echo Step A
goto :eof

:StepB
    echo Step B
goto :eof

:StepC
    echo Step C
goto :eof

像这样工作:

c:\>Menu.cmd
Enter Choice(s) (A,B,C) b c a
b c a
Step B
Step C
Step A

答案 2 :(得分:1)

您可以使用start "" command关键字,每个命令都会在其自己的窗口中运行,但由菜单批处理文件启动。