Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing 从批处理文件设置errorlevel_Unit Testing_Batch File_Testing_Error Handling_Scripting - Fatal编程技术网

Unit testing 从批处理文件设置errorlevel

Unit testing 从批处理文件设置errorlevel,unit-testing,batch-file,testing,error-handling,scripting,Unit Testing,Batch File,Testing,Error Handling,Scripting,我正在研究这个复杂的(对我来说…)自动化,其中一部分是从另一部分启动(未调用)的批处理脚本 现在,所有的工作都在进行中,我希望能够用一条简单的指令来替换启动的批处理脚本,这样在启动子脚本之后,启动脚本就可以: %ERRORLEVEL%EQU 1 (然后我可以处理错误处理方面和测试内容) 但也有一些很好的东西,不会让系统处于不自然的状态(我可能会根据这种不好的状态编写脚本,并想知道为什么当我组装所有这些东西时,它们都不工作)

我正在研究这个复杂的(对我来说…)自动化,其中一部分是从另一部分启动(未调用)的批处理脚本

现在,所有的工作都在进行中,我希望能够用一条简单的指令来替换启动的批处理脚本,这样在启动子脚本之后,启动脚本就可以:
%ERRORLEVEL%EQU 1 (然后我可以处理错误处理方面和测试内容)

但也有一些很好的东西,不会让系统处于不自然的状态(我可能会根据这种不好的状态编写脚本,并想知道为什么当我组装所有这些东西时,它们都不工作)<所以,“C-q格式”不起作用


谢谢

cmd/c exit 1
会将errorlevel设置为
1
如果您想让用户输入errorlevel,可以使用
选项
命令

@echo off
choice /c 123456789
echo %errorlevel%
根据您在
选项
命令的顺序上键入的内容,errorlevel将从
1
开始设置

例如:

choice /c dghet

按“d”将使
errorlevel
1,按h将使
errorlevel
3。还有一个额外的好处是,输入后不需要按enter键。

我认为这个问题应该被替换为
如何设置非零错误级别?我需要它来测试批处理文件中的错误处理例程。
这不是我想要的,但它非常酷!谢谢