- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
重定向失败时(由于文件不存在或文件访问不足),似乎未设置ErrorLevel
值(在以下示例中,文件test.tmp
受写保护,并且文件test.nil
不存在):
>>> (call ) & rem // (reset `ErrorLevel`)
>>> > "test.tmp" echo Text
Access is denied.
>>> echo ErrorLevel=%ErrorLevel%
ErrorLevel=0
>>> (call ) & rem // (reset `ErrorLevel`)
>>> < "test.nil" set /P DUMMY=""
The system cannot find the file specified.
>>> echo ErrorLevel=%ErrorLevel%
ErrorLevel=0
||
(正在查询退出代码),
ErrorLevel
就会意外地设置为
1
:
>>> (call ) & rem // (reset `ErrorLevel`)
>>> (> "test.tmp" echo Text) || echo Fail
Access is denied.
Fail
>>> echo ErrorLevel=%ErrorLevel%
ErrorLevel=1
>>> (call ) & rem // (reset `ErrorLevel`)
>>> (< "test.nil" set /P DUMMY="") || echo Fail
The system cannot find the file specified.
>>> echo ErrorLevel=%ErrorLevel%
ErrorLevel=1
ErrorLevel
时,
0
仍为
&&
:
>>> (call ) & rem // (reset `ErrorLevel`)
>>> (> "test.tmp" echo Text) && echo Pass
Access is denied.
>>> echo ErrorLevel=%ErrorLevel%
ErrorLevel=0
>>> (call ) & rem // (reset `ErrorLevel`)
>>> (< "test.nil" set /P DUMMY="") && echo Pass
The system cannot find the file specified.
>>> echo ErrorLevel=%ErrorLevel%
ErrorLevel=0
ErrorLevel
,
0
仍然是
&
:
>>> (call ) & rem // (reset `ErrorLevel`)
>>> (> "test.tmp" echo Text) & echo Pass or Fail
Access is denied.
Pass or Fail
>>> echo ErrorLevel=%ErrorLevel%
ErrorLevel=0
>>> (call ) & rem // (reset `ErrorLevel`)
>>> (< "test.nil" set /P DUMMY="") & echo Pass or Fail
The system cannot find the file specified.
Pass or Fail
>>> echo ErrorLevel=%ErrorLevel%
ErrorLevel=0
&&
和
||
,
ErrorLevel
也设置为
1
(如果
||
出现在
&&
之前,则两个分支都如上一个示例中那样执行,但是我认为这只是因为
&&
评估了前面
echo
命令的退出代码):
>>> (call ) & rem // (reset `ErrorLevel`)
>>> (> "test.tmp" echo Text) && echo Pass || echo Fail
Access is denied.
Fail
>>> echo ErrorLevel=%ErrorLevel%
ErrorLevel=1
>>> (call ) & rem // (reset `ErrorLevel`)
>>> (< "test.nil" set /P DUMMY="") || echo Fail && echo Pass
The system cannot find the file specified.
Fail
Pass
>>> echo ErrorLevel=%ErrorLevel%
ErrorLevel=1
ErrorLevel
值和
||
运算符之间的联系是什么,为什么
ErrorLevel
受
||
影响?
||
是否将退出代码复制到
ErrorLevel
?所有这些都只能通过(失败的)重定向来完成,因为重定向是在执行任何命令之前进行的?
ErrorLevel
替换
0
(将
&&
最初设置为
(call )
),清除读取的内容时,我无法观察到相反的行为-
(call)
由
ErrorLevel
重置为
1
)。仅文件
test.tmp
的属性,创建文件
test.nil
(第一行不为空,以避免
set /P
将
ErrorLevel
设置为
1
),并使用文件扩展名
.bat
而不是
.cmd
进行测试(以避免
set /P
将
ErrorLevel
重置为
0
)。
最佳答案
我是在大约5年前在File redirection in Windows and %errorlevel%首次发现这种不合逻辑的行为的。两个月后,我在batch: Exit code for "rd" is 0 on error as well上发现了RD(RMDIR)命令的相同问题。最后一个问题的标题实际上是令人误解的,因为发生故障的RD的返回码非零,但是ERRORLEVEL与执行命令之前的值保持不变。如果返回码确实为0,则||
运算符将不会触发。
Is all this only possible with (failed) redirections, because such are handled before any commands are executed?
||
正在响应重定向操作的非零返回码。如果重定向失败,则命令(在您的情况下为ECHO)将永远不会执行。
So what is the connection between the ErrorLevel value and the || operator, why is ErrorLevel affected by ||? Is || copying the exit code to ErrorLevel?
||
代码。但是在少数情况下,开发人员由于不遵守规则而引入了错误。重定向失败或RD失败后,开发人员成功调用了
||
代码,但未能正确设置ERRORLEVEL。
||
的开发人员做了一些防御性编程。在执行
||
代码之前,ERRORLEVEL应该已经设置为非零。但是我认为
||
开发人员明智地不信任他/她的同龄人,因此决定在
||
处理程序中也设置ERRORLEVEL。
||
将原始返回码值转发给ERRORLEVEL。这意味着原始返回码必须已经存储在不同于ERRORLEVEL的某个临时存储区中。我有两个证据支持这一理论:
||
operator sets at least 4 different ERRORLEVEL values when RD fails, depending on the type of error。
||
设置的ERRORLEVEL与CMD/C设置的值相同,而CMD/C只是转发上一个命令/操作的返回码。
C:\test>(call )&rd .
The process cannot access the file because it is being used by another process.
C:\test>echo %errorlevel%
0
C:\test>(call )&rd . || rem
The process cannot access the file because it is being used by another process.
C:\test>echo %errorlevel%
32
C:\test>(call )&cmd /c rd .
The process cannot access the file because it is being used by another process.
C:\test>echo %errorlevel%
32
C:\test>invalidCommand
'invalidCommand' is not recognized as an internal or external command,
operable program or batch file.
C:\test>echo %errorlevel%
9009
||
运算符或CMD/C,则ERRORLEVEL为1:-/
C:\test>invalidCommand || rem
'invalidCommand' is not recognized as an internal or external command,
operable program or batch file.
C:\test>echo %errorlevel%
1
C:\test>(call )
C:\test>cmd /c invalidCommand
'invalidCommand' is not recognized as an internal or external command,
operable program or batch file.
C:\test>echo %errorlevel%
1
||
的情况下设置9009 ERRORLEVEL的代码必须执行某种类型的上下文相关转换以生成9009的方式来解决此异常问题。将 native 返回码转发到ERRORLEVEL,覆盖已经存在的9009值。
||
提供不同的非零ERRORLEVEL值。
Even more strangely, I could not observe the opposite behaviour -- ErrorLevel being reset to 0 by && --, when correctly reverting the test setup (that is, replacing (call ) by (call) (to set ErrorLevel to 1 initially), clearing the read-only attribute of file test.tmp, creating file test.nil (first line not empty to avoid set /P to set ErrorLevel to 1), and using file extension .bat rather than .cmd for testing (to avoid set /P to reset ErrorLevel to 0)).
||
清除了保留的错误,那么保留先前的错误并没有多大用处。
关于windows - 为什么仅在||之后才设置ErrorLevel重定向失败时的运算符(operator)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41318027/
登录Desktop Rstudio后,会出现以下消息: Error in yaml.load(readLines(con), error.label = error.label, ...) : o
在 cmd.exe 中运行 MS DOS 命令后,我使用 echo %ERRORLEVEL% 检查退出代码。不过我想在运行这个之前我应该清除变量:%ERRORLEVEL%。 我说得对吗?另外如何清
我想读取Java中cmd命令的返回码。为此,我使用了: Runtime.exec("echo %errorlevel%") 但不是回显错误代码,而是回显 %errorlevel%。 最佳答案 不知道你
我有一个嵌套的批处理脚本,我希望它的错误代码渗透到调用它的主批处理脚本。我试过了 exit /b %errorlevel% 但是变量没有返回。调用的批处理脚本中的 ECHO'ing %errorlev
我正在尝试以下命令并希望退出我的process(%ERRORLEVEL%)。但它返回 previous(last) 执行 sample.exe 的退出代码结果。我想获取当前命令的退出代码。我的要求是在
在启动 Jmeter 时,出现以下错误: VM 初始化期间发生错误无法为对象堆保留足够的空间 errorlevel=1。 请帮我解决这个问题。我使用的是 4GB RAM、64 位操作系统、intel
我正在学习 Windows 批处理脚本。当复制、移动或删除操作失败时,我需要提出错误。我制作了一个示例脚本,由于某种原因,当操作失败时,我无法让 ERRORLEVEL 上升。我运行脚本,文件不存在或在
我正在使用 Windows 批处理文件比较来自 2 个文件夹的文件列表。它打印结果,无论是通过还是失败。 当前工作批处理文件: for /F "tokens=*" %%f in (list.txt)
刚刚用 %ERRORLEVEL% 偶然发现了一件奇怪的事情并想看看是否有人知道原因以及是否有办法解决它。本质上,似乎在 if 语句中执行的命令没有设置 %ERRORLEVEL%多变的。 ERRORLE
由于 ERRORLEVEL 是一个环境变量,所以在我有机会在我的批处理文件中检查它之前,是否可以更改它的值? 最佳答案 环境变量属于当前“进程”,因此无法从外部更改它们。如果您在批处理文件中的相关命令
我试图找到一种方法来查看主机是否在 Windows 的 C 中处于事件状态,因此我使用 ping 命令运行系统,然后运行系统检查 %ERRORLEVEL% 但它始终显示 0,即使主机无法访问也是如此.
在命令提示符下,试试这个: powershell aaa echo ErrorLevel is %errorlevel% Powershell 将失败(出现错误)。您还会看到“ErrorLevel i
假设我们想使用以下命令在 Windows 中创建一个空文件: type nul > C:\does\not\exist\file.txt 目录不存在,所以报错: The system cannot f
我有一个为 C# 项目运行一些命令的构建后事件。最后一个命令有时会导致 ERRORLEVEL 值不等于零,然后构建失败。 我想附加一行额外的命令以始终将 ERRORLEVEL 值设置为零。最方便的方法
我的 Windows 机器桌面上有一个最小的批处理脚本,它使用 FC.exe 工具,用于比较我桌面上的两个文本文件。 我要比较的文件 file1.txt 包含一个字符 a file2.txt 包含一个
我想使用“wmic”命令来确定特定的 java 进程是否仍在运行。 例如> wmic 进程,其中“commandLine like '%ACTMonitor%' and executablePath
我试图从作为 QProcess 运行的 Windows 命令行应用程序中捕获特定的错误代码。 我今天有一个错误,应用程序失败: 在命令行上运行时: echo %errorleve% 返回 14001
我们有一个程序偶尔会崩溃。客户从计划任务运行程序。当程序以特定参数运行时,程序作为接口(interface)引擎运行,创建一个文件,然后将该文件ftp'到另一个服务器以供另一个程序导入。 我想知道我是
Windows shell 有一个 %ERRORLEVEL% 变量,可用于查找已通过 shell 运行的进程的退出代码。因此,我可以在 .bat 文件中使用它来获取我从 .bat 文件中调用的外部脚本
我想知道是否可以从 Ant build xml 中的批处理文件获取返回值。 我的批处理文件返回 %ERRORLEVEL% 值(在我的情况下,批处理文件返回 2)。我想知道是否可以捕获此问题并在 Ant
我是一名优秀的程序员,十分优秀!