【问题标题】:batch command input menu批处理命令输入菜单
【发布时间】:2013-05-21 11:35:39
【问题描述】:

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

示例:(我的代码)

@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,3,5要同时执行?

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

【问题讨论】:

    标签: batch-file batch-processing


    【解决方案1】:

    建议:将callgoto 组成,并将命令与& 连接:

    如果 /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 如果 /I '%INPUT%'=='5' CALL:Selection5 如果 /I '%INPUT%'=='6' CALL:Selection6 如果 /I '%INPUT%'=='7' CALL:Selection7 如果 /I '%INPUT%'=='8' CALL:Selection8 如果 /I '%INPUT%'=='9' CALL:Selection9 如果 /I '%INPUT%'=='Q' GOTO:Quit

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

    :选择2 调用 cleanup.bat 转到:eof :选择3 还有在这里... 转到:eof :选择4 等等 转到:eof :选择5 等等 转到:eof ... .. .

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

    【讨论】:

    • 另一个问题,如何将 .exe 撤消回 .bat?有这样的程序吗?
    【解决方案2】:

    这就是你要找的吗?

    文件菜单.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
    

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-19
        相关资源
        最近更新 更多