简体   繁体   English

在批处理文件中使用管道命令

[英]Using pipe command in a batch file

I'm trying to write a batch file that searches through devices using devcon and then runs "devcon enable" on these devices. 我正在尝试编写一个批处理文件,该文件使用devcon搜索设备,然后在这些设备上运行“ devcon enable”。

My batch file looks like this: 我的批处理文件如下所示:

for /f "tokens=1 delims=:" %%i in ('devcon find *VENDER_INFO* ^| findstr /C:"DEVICEINFO"') do devcon enable "@"%%i

You can ignore the " VENDER_INFO " and "DEVICEINFO" as I simply redacted these to make the commands easier to read. 您可以忽略“ VENDER_INFO ”和“ DEVICEINFO”,因为我只是对它们进行了编辑,以使命令更易于阅读。

When I run this.bat file, It appears as though the 当我运行this.bat文件时,好像

devcon find *VENDER_INFO* ^| findstr /C:"DEVICEINFO"

command is only running the first part and failing to pipe the results through 命令仅运行第一部分,并且无法通过管道传递结果

findstr /C:"DEVICEINFO"

Can you see anything wrong with my .bat file? .bat文件有什么问题吗? Why is it ignoring the pipe and second part of the find command? 为什么忽略管道和find命令的第二部分? I tried removing the "^" but this fails and says "|" 我尝试删除“ ^”,但是失败并显示“ |” was unexpected. 出乎意料。

The find command requires double quotes. find命令需要双引号。

Read the help with this: 阅读有关此内容的帮助:

find /?

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

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