这是一个简单的批处理文件,它演示了如果延迟扩展在正在通过管道传输的块中,它将如何失败.(失败是在脚本的末尾)任何人都可以解释为什么这是?
我有一个解决方法,但它需要创建一个临时文件.我最初在查找文件时遇到了这个问题,并在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)