简体   繁体   English

Windows批处理-ECHO正在更改%ERRORLEVEL%

[英]windows batch - ECHO is changing the %ERRORLEVEL%

I have the following .bat snippet 我有以下.bat片段

echo about to start echoing, Errorlevel=%Errorlevel%

echo. >> ../time.txt

echo Just echod a new line into time.txt, Errorlevel=%Errorlevel%

echo | set/p=start=%time%, >> ../time.txt    

echo about to start with emake, Errorlevel=%ERRORLEVEL%

The output is: 输出为:

about to start echoing, Errorlevel=0
Just echod a new line into time.txt, Errorlevel=0
about to start with emake, Errorlevel=1

Why is the line echo | set/p=start=%time%, >> ../time.txt 为什么行echo | set/p=start=%time%, >> ../time.txt echo | set/p=start=%time%, >> ../time.txt changing the %ERRORLVEL% ? echo | set/p=start=%time%, >> ../time.txt更改%ERRORLVEL%吗?

That lines sets ERRORLEVEL to 1 because SET /P fails (sets ERRORLEVEL to 1) whenever it fails to set a value, and your set/p=start=%time%, will never set a value. 该行将ERRORLEVEL设置为1,因为SET /P每次未能设置值时都会失败(将ERRORLEVEL设置为1),并且您的set/p=start=%time%,将永远不会设置值。 Everything after the first = is considered to be the prompt, so there is no variable, and the command will always "fail". 第一个=之后的所有内容都被视为提示,因此没有变量,该命令将始终“失败”。

I have no idea what you are attempting to do with that line, so I can't give you a solution. 我不知道您打算如何处理该行,因此无法为您提供解决方案。 But one thing you should be aware of - SET /P is useless for setting variables if used within a pipe . 但是您应该意识到的一件事-SET / P对于在管道中使用设置变量是没有用的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM