Help - Search - Members - Calendar
Full Version: command won't execute in batch file
ieXbeta Board > Tech > Developer Center
dkreifus
I'm trying to write a little script to extract a computers location in LDAP and save it as variables, so I can store it in a custom location in the registry.

On a normal command line, I type
CODE
set B=dsquery computer -name %computername%
FOR /F "tokens=3,4,5 delims=,OU=" %i in ('%B%') do @echo %i %j %k


But in a batch script, it fails completely and says:
QUOTE
Bi was unexpected at this time.
FOR /F "tokens=2,3,4 delims=,OU=" Bi k

I'm new to using the FOR command, so I'm pretty stumped.

EDIT:
I finally figured it out...
CODE
set B=dsquery computer -name %computername%
FOR /F "tokens=3,4,5 delims=,OU=" %%i in ('%B%') do SET i=%%i&&set j=%%j&&set k=%%k

I needed to make it a double % in a batch file.
Taco Bell
I haven't used the FOR command either dk, but after some trial & error along with some Googling, I figured it out.

According to this reference page, in a batch file you must use double % for the parameter portion.

Therefore, the working code is as follows:

CODE
set B=dsquery computer -name %computername%
FOR /F "tokens=3,4,5 delims=,OU=" %%i in ('%B%') do @echo %i %j %k

---

Oh, I now see by your edit that you came to the same conclusion! wink2.gif
dkreifus
thanks for your help though!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.