Solved [batch] use input to search for output.

January 24, 2011 at 17:19:44
Specs: Windows 7
am trying to write a script to find the correct driver.

W:\win7>devcon listclass display
Listing 2 device(s) for setup class "Display" (Display adapters).
PCI\VEN_10DE&DEV_0CA3&SUBSYS_00000000&REV_A2\4&2FAE9228&0&0008: NVIDIA GeForce GT 240
ROOT\DISPLAY\0000 : VNC Mirror Driver

Of these, I want to grab "PCI\VEN_10DE&DEV_0CA3" and use this to search inf files in folders. this part i probably can do. so what I don't know how to do is to grab the variable.

findstr /s /c:"PCI\VEN_10DE&DEV_0CA3" "c:\drivers\*.inf"

oh yeah, will i need to escape "&" ?

.


See More: [batch] use input to search for output.

Report •

#1
January 25, 2011 at 15:55:37
above command will do search for the the srting you mentioned.

Which variable you would like to grab ?

Subhash Chandra.
www.s-chandra.co.cc


Report •

#2
January 25, 2011 at 16:25:07
W:\win7>devcon listclass display
~~~~~~~~~~
Listing 2 device(s) for setup class "Display" (Display adapters).
PCI\VEN_10DE&DEV_0CA3&SUBSYS_00000000&REV_A2\4&2FAE9228&0&0008: NVIDIA GeForce GT 240
ROOT\DISPLAY\0000 : VNC Mirror Driver
~~~~~~~~~~

Input is between ~~~~~~~~

It should grab PCI\VEN_10DE&DEV_0CA3 out of that, which will be used to search in the latter part, which I'm able to achieve.

.


Report •

#3
January 25, 2011 at 17:44:35
✔ Best Answer
for /f "tokens=1,2 delims=&" %%a in (' devcon listclass display ^| findstr /b "PCI\\VEN_" ') do echo findstr "%%a&%%b"


Report •

Related Solutions

#4
January 25, 2011 at 19:32:10
Judago, would you need to escape the & in the findstr? Or is there a secret you know?

Can I put a question here?


Report •

#5
January 25, 2011 at 19:46:15
Only if it wasn't double quoted.


If it's contained in double quotes it's normally fine as is, but just to make things tricky carets"^" also survive when inside double quotes, so you can't just blindly escape.

echo ^&
echo "^&"
echo "^"&echo "i"

Edit:
Forgot to mention that if unmatched the last double quote will escape the rest of the line.

echo "><|&^


Report •

#6
January 25, 2011 at 21:16:47
Ahh, thanks Judago.

Can I put a question here?


Report •

Ask Question