如何获取用户输入 - 批? [英] How to get user input - batch?

查看:163
本文介绍了如何获取用户输入 - 批?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想code可选,用户可以在其中输入y或n,关机。而这也正是我一直在努力:

So I want to code an optional, where the user can input y or n, shut down. And this is what I have been trying:

    @echo off
    echo                                      ---WARNING---
    echo.
    echo DO YOU WANT YOUR COMPUTER TO SHUTDOWN? (y/n)
    If /I "%Input%"=="y" goto yes
    If /I "%Input%"=="n" goto no
    :yes
    shutdown /s
    :no
    pause

我是沿着正确的轨道,甚至?

Am I along the right track even?

推荐答案

尝试添加这一点。我还增加了一个跳转,因为如果你输入的东西是不是一个一个是不那么它会自动去肯定的。

Try adding this. I have also added a goto because if you typed something that isn't a yes of a no then it would of automatic gone to yes.

set /p Input=Enter Yes or No:

未能通过下面code你可以添加这一点,但在底部code应该工作。

Failing the below code you could add this but the code at the bottom should work.

set /P INPUT=Type input: %=%
If %INPUT%=="y" goto yes 
If %INPUT%=="n" goto no

您code应该是这样的:

Your code should be like this:

@echo off
echo                                      ---WARNING---
echo.
echo DO YOU WANT YOUR COMPUTER TO SHUTDOWN? (y/n)
set /p Input=Enter Yes or No:
If /I "%Input%"=="y" goto yes
goto no
:yes
shutdown /s
:no
pause

这篇关于如何获取用户输入 - 批?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆