简体   繁体   English

如何使用 pipe 过滤批处理文件?

[英]How to filter batch file with pipe?

I am trying to filter (git staged) files and concatenate it.我正在尝试过滤(git staged)文件并将其连接起来。 I am getting error as file not found.由于找不到文件,我收到错误消息。 refer参考截屏

set List='git diff --cached --name-only --diff-filter=ACMR'
set output=
for /f "delims=" %%a in (%List%) do ( 
      (Echo "%%a"| find ".java" set output=!output! "%%a") || (
    REM    set output=!output! "%%a" 
   ))
echo %output%

Thanks in advance!提前致谢!

Unless I've misunderstood what you're doing, it would make it much more efficient if you filtered the results within the parenthesized command instead of the `do` portion: 除非我误解了您在做什么,否则如果您在带括号的命令而不是“do”部分过滤结果,它会更有效:
 @Set "ListCommand='git diff --cached --name-only --diff-filter^=ACMR ^^^| "%%__AppDir__%%findstr.exe" /L /I /E ".java"'" @Set "output=" @For /F Delims^= %%G In (%ListCommand%)Do @If Not Defined output (Set output="%%~G")Else Set "output=!output! "%%~G"" @Echo %output%

This assumes that you have delayed expansion enabled, and that none of your returned file names contain exclamation marks.这假定您已启用延迟扩展,并且您返回的文件名都不包含感叹号。 It also assumes that you do not have too many returned filenames, otherwise the size of the environment could be exceeded.它还假设您没有太多返回的文件名,否则可能会超出环境的大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM