首页 > 解决方案 > 如何将多管道命令的输出分配给 Windows CMD 批处理中的变量?

问题描述

我需要遍历目录中的一组文件,匹配通配符模式并在其他两个模式之间提取文件名的一部分。Unix(即 bash)等效命令将是这样的:

ls -1 "$wildcard1"*"$wildcard2" | while read filename; do
string2find=`echo $filename | cut -d $delim1 -f2 | cut -d $delim2 -f1`
echo $string2find
#do something with string2find variable here
done

在批处理文件中,我尝试了这个

for %%f in (WILD1*WILD2) do (

echo %%f | cut -d_ -f2 | cut -d"." -f1> temp.out  <--here, need something between an "_" and a "."
type temp.out <-- see the right string in the file
set var=   <clear the variable
set /p var=<temp.out
echo %var% <-- ECHO is off message I am getting here 
del temp.out
REM need to do something with var here

)

我能找到的所有示例都没有管道命令。

标签: batch-filevariables

解决方案


推荐阅读