简体   繁体   中英

Executing a pipe line command with findstr

I am trying to get the name of a file containing a particular string. The following command does that.

dir /a:-D /b | findstr /i "fileName.jar"

I'm trying to run it through a bat file using the following code.

for /F "delims=" %%a in ('dir /a:-D /b | findstr /i "fileName.jar"') do set "batToolDir=%%a"

But I am getting the below error.

| was unexpected at this time.

I need to get the name of the file containing a certain string. How can I achieve this? Any help would be much appreciated.

"below error" ??

What you need is to escape the | to tell cmd that the pipe is part of the command to be executed, not of the for . You need to do this with all redirectors.

The escape character is ^ , so substitute ^| for | within the parentheses. ANy such awkwardness, try inserting ^ before the character causing the problem...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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