Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.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
Windows cmd提示符和win32_进程上ERRORLEVEL延迟扩展的差异_Windows_Batch File_Cmd - Fatal编程技术网

Windows cmd提示符和win32_进程上ERRORLEVEL延迟扩展的差异

Windows cmd提示符和win32_进程上ERRORLEVEL延迟扩展的差异,windows,batch-file,cmd,Windows,Batch File,Cmd,它打印出来了!错误级别 当我使用WMI win32_进程创建命令运行该命令时,这确实可以正常工作,并且使用返回正确的错误!错误等级!变数 在cmd提示符中执行和使用WMI win32_进程执行时有什么区别 cmd /V:ON /c dir c:\ERt & echo !ERRORLEVEL! Volume in drive C is PC COE Volume Serial Number is 9C37-D0B7 Directory of c:\ File Not Found

它打印出来了!错误级别

当我使用WMI win32_进程创建命令运行该命令时,这确实可以正常工作,并且使用返回正确的错误!错误等级!变数

在cmd提示符中执行和使用WMI win32_进程执行时有什么区别

cmd /V:ON /c dir c:\ERt & echo !ERRORLEVEL!
 Volume in drive C is PC COE
 Volume Serial Number is 9C37-D0B7

 Directory of c:\

File Not Found
!ERRORLEVEL!
新的命令进程从
cmd/V:ON
开始,只执行命令
dir c:\ERt
,然后关闭,第二个命令
echo!错误等级由未启用延迟扩展的当前命令进程执行

命令行

cmd /V:ON /c dir c:\ERt & echo !ERRORLEVEL!
必须用于运行
dir c:\ERt
echo!错误等级

在新命令过程中要执行的整个命令行周围的双引号起了作用

在新命令进程中,如果命令行周围没有双引号,则当前命令进程会将包含两个命令的行解释为键入时的行

cmd /V:ON /c "dir c:\ERt & echo !ERRORLEVEL!"
也可能是

cmd /V:ON /c dir c:\ERt
echo !ERRORLEVEL!

现在,
&
运算符被转义,因为当前命令进程被解释为文字字符,因此整行将使用新命令进程删除的插入符号
^
执行。

echo
命令在父
cmd
实例的范围内运行,但不在当前实例中运行明确启动;写入
^&
以转义符号,因此它将在预期的
cmd
实例中执行。。。
cmd /V:ON /c dir c:\ERt
echo !ERRORLEVEL!
cmd /V:ON /c dir c:\ERt ^& echo !ERRORLEVEL!