Brackets in FOR command?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello!

I run into a problem I was not able to solve by myself and by googleing.
It's a longer post for command line wizards only.

Win2k environment.
I use FOR frequently to scan command line outputs for certain strings for
further processing. By the way: Kudos for the posters here. Learned a lot
about scripting from you.


Example:
===CHECK.CMD===
FOR /F %%a in ('ping %1 -n 1^|find /i "Answer from"') do call %2 %1
===EOF===
Or
===CHECKVERSION.CMD===
for /f "tokens=6 delims=\" %%a in ('reg query
\\%1\HKLM\software\internal\censored\nda^|find /i "nda\"') do <nul (set /p
xxx=%%a;) >> ..\log\checkversion.log
===EOF===

Now I want to use DEVCON to check version info for installed device drivers
(example: display adapter).

DEVCON driverfiles =display|find /I "Driver installed"

gives me the line with the INF to look for this information. No trouble so
far. I planned to extract the file name, using something like

FOR /F "tokens=2 delims==" %%a in ('Type <filename>^|find /I
"Basedriverfileversion="') do <something useful>

Okay, I that's the concept.
But I failed. Failed completely!
The FOR command for the first step won't work at all (command line version
for testing follows)

FOR /F "delims=;" %a in ('DEVCON driverfiles =display^|find /I "Driver
installed"') do echo %a

won't do anything.
I tried
FOR /F %a in ('DEVCON driverfiles =display') do echo %a
and the result was "No". Well, I appreciate that irony from the command line
interface.
The complete string is "No matching devices found".
Looks like the combination of FOR and DEVCON would allow me to add strings
after "display" because they will be interpreted as additional strings for
the DEVCON command. I tried to remember what I learned about encapsulation
and used brackets inside the command line and tested.
(DEVCON driverfiles =display)
worked fine. But I was not able to combine FOR with this method. None of
this will work:
FOR /F %a in ('(DEVCON driverfiles =display)') do echo %a
FOR /F %a in (('DEVCON driverfiles =display')) do echo %a

My big question: How to use "double brackets" in FOR? Or any other idea to
solve this using FOR?
Good for me: It's not urgent. I just want to know how to solve this riddle.

Ciao, Walter
 
This-line-intentionally-left-blank said:
Hello!

I run into a problem I was not able to solve by myself and by
googleing. It's a longer post for command line wizards only.

Win2k environment.
I use FOR frequently to scan command line outputs for certain strings
for further processing. By the way: Kudos for the posters here.
Learned a lot about scripting from you.


Example:
===CHECK.CMD===
FOR /F %%a in ('ping %1 -n 1^|find /i "Answer from"') do call %2 %1
===EOF===
Or
===CHECKVERSION.CMD===
for /f "tokens=6 delims=\" %%a in ('reg query
\\%1\HKLM\software\internal\censored\nda^|find /i "nda\"') do <nul
(set /p xxx=%%a;) >> ..\log\checkversion.log
===EOF===

Now I want to use DEVCON to check version info for installed device
drivers (example: display adapter).

DEVCON driverfiles =display|find /I "Driver installed"

gives me the line with the INF to look for this information. No
trouble so far. I planned to extract the file name, using something
like

FOR /F "tokens=2 delims==" %%a in ('Type <filename>^|find /I
"Basedriverfileversion="') do <something useful>

Okay, I that's the concept.
But I failed. Failed completely!
The FOR command for the first step won't work at all (command line
version for testing follows)

FOR /F "delims=;" %a in ('DEVCON driverfiles =display^|find /I "Driver
installed"') do echo %a

won't do anything.
I tried
FOR /F %a in ('DEVCON driverfiles =display') do echo %a
and the result was "No". Well, I appreciate that irony from the
command line interface.
The complete string is "No matching devices found".
Looks like the combination of FOR and DEVCON would allow me to add
strings after "display" because they will be interpreted as
additional strings for the DEVCON command. I tried to remember what I
learned about encapsulation and used brackets inside the command line
and tested. (DEVCON driverfiles =display)
worked fine. But I was not able to combine FOR with this method. None
of this will work:
FOR /F %a in ('(DEVCON driverfiles =display)') do echo %a
FOR /F %a in (('DEVCON driverfiles =display')) do echo %a

My big question: How to use "double brackets" in FOR? Or any other
idea to solve this using FOR?
Good for me: It's not urgent. I just want to know how to solve this
riddle.

Ciao, Walter

Try escaping the "=" symbol by placing a carat "^" in front of it like
this -

FOR /F %a in ('DEVCON driverfiles ^=display') do echo %a
 
None
Try escaping the "=" symbol by placing a carat "^" in front of it like
this -
FOR /F %a in ('DEVCON driverfiles ^=display') do echo %a

Thanks a lot, it is working.

That's my command (command line version, single line (no CR/LF)):
FOR /F "tokens=4" %a in ('devcon driverfiles ^=display^|find /i "Driver
installed"') do @FOR /F "tokens=2 delims== " %b in ('type %a^|find /i
"Basedriverfileversion="') do @echo %b

Output will show the version info for the display drivers.

Ciao, Walter
 
Back
Top