Command line 与'有关的问题;呼叫';批处理命令

Command line 与'有关的问题;呼叫';批处理命令,command-line,call,Command Line,Call,也许现在这里有个棘手的问题 我有一个脚本,它要求一个必填字符串,不能为空。如果为空,则返回错误: @echo off set $my_var= :my_question cls set /p $my_var="My question (mandatory): " if not defined $my_var call :error_message echo. echo More code here goto end :error_message echo. powershell -com

也许现在这里有个棘手的问题

我有一个脚本,它要求一个必填字符串,不能为空。如果为空,则返回错误:

@echo off

set $my_var=

:my_question
cls
set /p $my_var="My question (mandatory): "
if not defined $my_var call :error_message

echo.
echo More code here
goto end

:error_message
echo.
powershell -command write-host "*********** ATTENTION ************" -background red -foreground yellow
echo.
echo Answer is mandatory. Press ENTER!
pause > nul
goto my_question

:end
echo.
set $my_var=
echo.
echo Ended
但是如果用户输入错误,比如说3次,那么第一次
回显。
转到结束
之间的代码将重复3次。
:end
部分也会重复。
:error\u code
中的消息不会重复:

My question (mandatory): 6

More code here


Ended

More code here


Ended

More code here


Ended

More code here


Ended
它甚至忽略了
转到end
命令!我希望避免将error_消息的代码放在括号中,因为我将不得不使用goto命令,并且可能会破坏我的代码,因为它比这多得多


“调用”有什么问题?

现在没有合适的测试环境可用…如果删除
设置$my\u var=
或更改(用于测试)后提示检查为
如果定义了$my\u var调用:错误消息
,会发生什么?谢谢。我现在不能测试,因为我做了一个变通方法。我只是把错误消息的代码放在括号里,然后在新的一行上加上一个goto