这是一个简单的批处理文件,它演示了如果延迟扩展在正在通过管道传输的块中,它将如何失败.(失败是在脚本的末尾)任何人都可以解释为什么这是?
我有一个解决方法,但它需要创建一个临时文件.我最初在查找文件时遇到了这个问题,并在Windows批处理文件中按大小排序
@echo off
setlocal enableDelayedExpansion
set test1=x
set test2=y
set test3=z
echo(
echo NORMAL EXPANSION TEST
echo Unsorted works
(
echo %test3%
echo %test1%
echo %test2%
)
echo(
echo Sorted works
(
echo %test3%
echo %test1%
echo %test2%
) | sort
echo(
echo ---------
echo(
echo DELAYED EXPANSION TEST
echo Unsorted works
(
echo !test3!
echo !test1!
echo !test2!
)
echo(
echo Sorted fails
(
echo !test3!
echo !test1!
echo !test2!
) | sort
echo(
echo …Run Code Online (Sandbox Code Playgroud) 有人可以解释一下它们之间的区别
call someBatchFile.bat ...
Run Code Online (Sandbox Code Playgroud)
和
cmd /C someBatchFile.bat ...
Run Code Online (Sandbox Code Playgroud)
他们都被建议我作为这个问题的解决方案,但我不明白为什么他们都工作,更重要的是,如果有任何重大的差异我必须意识到.