Set errorlevel from batch-file

不羁岁月 提交于 2019-12-31 03:11:23

问题


I am working on this complicated (for me...) automation and one part is a batch script Started (not Called) from another one.

Now, it's all work-in-progress and I'd like to be able to replace the Started batch script with a simple instruction that would do such that the Start-ing script, after having started the child script, has:
%ERRORLEVEL% EQU 1 (And then I could work on the error-handling aspects and test stuff)

But also something nice that doesn't put the system in an unnatural state (and I might script things according to that bad state and wonder why things don't work when I assemble it all).
So, "Format C -q" doesn't work! ;)

Thanks


回答1:


cmd /c exit 1 will set the errorlevel to 1.




回答2:


If you want to have user input errorlevel you can use the choice command.

@echo off
choice /c 123456789
echo %errorlevel%

Depending on what you type on the order of the choice command the errorlevel will be set starting at 1.

example:

choice /c dghet

pressing 'd' will make the errorlevel 1, and pressing h will make the errorlevel 3. Also as a perk you don't need to press enter after the input.



来源:https://stackoverflow.com/questions/33756407/set-errorlevel-from-batch-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!