返回到开始如果没有输入输入(BAT文件) [英] Go Back to Start If no input is entered (Bat File)
问题描述
好吧首先拥有所有我对我的英文不好对不起:)
现在我的问题。
我试图创造了多种选择一个脚本文件,我遇到了一个问题。
如果我不输入的输入(只是preSS进入)文件显示错误并关闭。
我现在的问题是,是否有一个命令,将强制文件回到开始在没有输入输入性病例?
我的脚本的这一相关部分
:输入
关闭@echo
CLS
ECHO #############################################
ECHO ##
ECHO#1 - 使系统文件夹或文件#
ECHO#2 - 恢复文件夹或文件#
回声#3 - 退出#
ECHO ##
ECHO #############################################SET / p O =设置您的选择和preSS输入:
ECHO加载.........
(
IF%。O%== 1 GOTO隐藏
IF%。O%== 2 GOTO展
IF%。O%== 3 GOTO退出
IF%。O%==GOTO输入
)
ELSE(
GOTO输入
)
正如你可以看到我试图用其他,但它只能部分。
如果我进入一个变量,没有给出列表的一部分(在我的情况1,2,3)文件GOSE回到起点,甚至如果我发送非输入请求后记文件继续正常工作。
这个问题是非常具体的,仅当所述第一输入是一个非输入的问题发生。
在任何其他情况下的脚本正常工作
感谢您,我再次为我的英语不好很遗憾:)
-
输入之前,请务必复位变量。当用户只需presses输入变量不会自动复位。
::删除变量%。O%
SETO =
SET / PO =设置您的选择和preSS输入: -
始终以变量引号(中频)
IF%。O%==1GOTO隐藏
IF%。O%==2GOTO展
IF%。O%==3GOTO退出 -
GOTO标签
永远不会返回了。你的情况,你可以这样写:IF%。O%==1GOTO隐藏
IF%。O%==2GOTO展
IF%。O%==3GOTO退出GOTO INPUT -
添加code更改之后的每个'步骤'命令
退出/ B
来prevent疯狂解析之后。警告:转到
命令不会像无效
在C ++中,这样的命令退出/ B工作
停止脚本。但是,如果你使用的是电话:标签
命令退出/ B
将停止code仅在:标签
。
( - :在某些情况下,疯狂的标签
转到除外)
Ok First have all i'm sorry for my poor english :) Now for my problem
I'm trying to create a Script file with multiple choices and I ran into a problem. If I don't enter an input (just press enter) the file displays an error and shuts down. now My question is whether there is a command that will force the file to go back to the Start in case where no input is entered?
This relevant part of my script
:input
@echo off
CLS
ECHO #############################################
ECHO # #
ECHO # 1 - Make A System Folder or File #
ECHO # 2 - Restore Folder or File #
Echo # 3 - Exit #
ECHO # #
ECHO #############################################
SET /P O=Set Your Choice And Press Enter:
ECHO Loading .........
(
IF %O%==1 GOTO Hide
IF %O%==2 GOTO Show
IF %O%==3 GOTO Exit
IF %O%=="" GOTO input
)
ELSE (
GOTO input
)
As you can see I tried to use "Else" but it works only partially. If I enter a variable that is not part of the list given (in my case 1, 2, 3) the File gose back to the beginning, and even if i send non input request afterword the file keep working properly. The problem is very specific, Only when the first input is a non input the problem Occurs. in any other situation the script works fine
Thank you and Again I'm very sorry for my poor English :)
Always reset variable before input. When user just presses enter variable doesn't reset automatically.
:: Delete variable %O% SET "O=" SET /P "O=Set Your Choice And Press Enter: "
Always take the variables in quotes (in IF)
IF "%O%"=="1" GOTO Hide IF "%O%"=="2" GOTO Show IF "%O%"=="3" GOTO Exit
GOTO Label
never returns back (exception -goto :label
in some crazy cases). In your case you can write:IF "%O%"=="1" GOTO Hide IF "%O%"=="2" GOTO Show IF "%O%"=="3" GOTO Exit GOTO INPUT
Add after each 'procedure' command
exit /B
to prevent crazy parsing after code changing. Warning:goto
command doesn't work likevoid
in C++, so commandexit /B
will stop script. But if you are usingcall :label
commandexit /B
will stop code only under:label
.
这篇关于返回到开始如果没有输入输入(BAT文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!