PC Review


Reply
Thread Tools Rate Thread

Brackets in FOR command?

 
 
=?Utf-8?B?VGhpcy1saW5lLWludGVudGlvbmFsbHktbGVmdC1i
Guest
Posts: n/a
 
      7th Sep 2004
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
 
Reply With Quote
 
 
 
 
Dean Wells [MVP]
Guest
Posts: n/a
 
      7th Sep 2004
This-line-intentionally-left-blank wrote:
> 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

--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l


 
Reply With Quote
 
=?Utf-8?B?VGhpcy1saW5lLWludGVudGlvbmFsbHktbGVmdC1i
Guest
Posts: n/a
 
      8th Sep 2004
> >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.


> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Brackets Khalil Handal Microsoft Excel Discussion 15 9th Aug 2009 05:21 PM
when are [ ] brackets used cmat Microsoft Excel Worksheet Functions 2 21st Oct 2008 10:35 PM
help with brackets =?Utf-8?B?dG9tYnJhZHNoYXd1aw==?= Microsoft Excel Misc 3 17th Nov 2006 10:19 PM
=D6-E6 there are brackets? =?Utf-8?B?SmlsbE0=?= Microsoft Excel Charting 1 21st Jul 2006 08:03 PM
Brackets Tork2001 Microsoft Outlook Contacts 4 22nd Jul 2003 04:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:47 AM.