且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么在管道块命令中进行“IF”比较时会出现错误消息?

更新时间:2023-11-25 13:45:16

试试这个:

set "myline=if 3 NEQ 2 echo yes"

( %myLin^e%)|sort

或来自批处理文件(双重扩展与批处理文件和控制台的工作方式不同):

or from batch file (double expansion works differently from batch file and the console):

set "myline=if 3 NEQ 2 echo yes"

( %%myLine%%)|sort

神秘由jeb 这里此处。虽然你在管道之前遇到了这个问题,但它是同一个bug,因为cmd在管道的每一边创建了两个线程。

The "mystery" was solved by jeb here and here . Though you are facing the issue before the pipe it is the same bug because the cmd creates two threads on each side of the pipe.

以下是for循环的制作方法工作:

Here's how the for loop can be made to work:

set "line=if %a NEQ 0"
(for /L %a in (1,1,9) do @( %lin^e% echo %a))|sort /R