小编Aci*_*cid的帖子

如何将 Windows 批处理 for 循环的最终结果通过管道传输到另一个命令中

将我的脚本分成两个批处理文件,因为我不知道如何组合它:

很短,这样你就明白了:

1.bat:使用参数调用 2.bat,对其输出进行排序并使行唯一

FOR /F ... (2.bat %1 ^| sort) DO (...)
Run Code Online (Sandbox Code Playgroud)

do 部分将行相互比较并使用行缓冲区排除相同的行

2.bat:打印 FOR 循环的结果字符串

FOR ... DO ECHO
Run Code Online (Sandbox Code Playgroud)

在 bash 中,这可能看起来像这样:(管道很容易)

(command) | while read line ; do echo $line ; done | sort | uniq
Run Code Online (Sandbox Code Playgroud)

我真的不知道如何在 Windows 批处理中处理 FOR 循环的最终输出,以将其结果与另一个循环一起使用(不使用临时文件进行结果缓冲)

这是应用 jeb 解决方案的完整代码:

@echo off
setlocal EnableDelayedExpansion

REM *** This "goto" to a label, if there is one embedded in %~0 -
FOR /F "delims=: tokens=3" %%L in ("%~0") do goto :%%L

REM …
Run Code Online (Sandbox Code Playgroud)

windows for-loop batch-file

2
推荐指数
1
解决办法
1736
查看次数

标签 统计

batch-file ×1

for-loop ×1

windows ×1