1

I'm trying to write a batch file that searches through devices using devcon and then runs "devcon enable" on these devices.

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.

When I run this.bat file, It appears as though the

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? Why is it ignoring the pipe and second part of the find command? I tried removing the "^" but this fails and says "|" was unexpected.

Paul
  • 2,620
  • 2
  • 17
  • 27
TrolliOlli
  • 909
  • 2
  • 10
  • 18
  • [Windows Device Console (DevCon.exe)](https://msdn.microsoft.com/en-us/library/windows/hardware/ff544707%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396) for reference. Are there any special characters in your `VENDER_INFO` string? – David Ruhmann Sep 21 '15 at 16:53
  • can you show the output of `devcon find *VENDER_INFO*`? And what you trying to match? – Paul Sep 21 '15 at 17:23
  • What you are doing works fine for me on my machine. Have you tried running the command separately without being inside the for loop and making sure it returns what you want? – lordjeb Sep 21 '15 at 17:37
  • 1
    The `^` in front of the pipe `|` is only needed when you parse the output of your `devcon` command line by a `for /F` loop; you said you ran the `devcon` stuff directly with `|` only (no `^`, no `for`) which failed; so you could try also `(devcon find *VENDER_INFO*) | findstr /C:"DEVICE_INFO"` directly... – aschipfl Sep 21 '15 at 18:09

1 Answers1

0

The find command requires double quotes.

Read the help with this:

find /?
foxidrive
  • 40,353
  • 10
  • 53
  • 68