views:

84

answers:

1

I am trying to write a small batch file for a task I do regularly. I have never used the for before and this is the first time I am trying this. This is what I have come with so far:

for /f %i in  ('ct find . -ver lbtype(%1) -print') do ct lsvt -g %i

Basically it tries find all the files with a given cleracase label and then display the version tree of those files. The problem is in the %1 . But when I try to run this sometime it gives me an error saying that -print ) was not expected or sometime else it just prints this command on the command prompt. I guess it is getting confused between multiple paranthesis. Any clues how o I solve this?

+3  A: 

Try quoting the command you're executing in the for:

for /f %i in  ('"ct find . -ver lbtype(%1) -print"') do ct lsvt -g %i

That worked for a similar command that I had that took args with parens.

Also, (as you're probably aware), you'll need to double-up on the '%' characters for the for variable when you put the command in a batch file instead of running it at the command line:

for /f %%i in  ('"ct find . -ver lbtype(%1) -print"') do ct lsvt -g %%i
Michael Burr
You'd propably want to quote the the `%%i` when dereferecing as it might contain file pathes with spaces. `... do ct lsvt -g "%%i"`
Frank Bollack
thanks..works perfectly.
Naveen
The double quotes there shouldn't do anything meaningful.
Joey
@Johannes: one thing to realize is that the single quotes aren't there to 'quote' the command, they're the syntax for the `for /f` command to execute a command and place the command's output into the `%i` variable. The other thing to realize is that parens have special meaning to cmd.exe, and they don't always seem to be handled cleanly by it. The double quotes definitely have meaningful effect, but I suppose it might be a cmd.exe bug that makes them necessary.
Michael Burr
I'd just escapethem with `^`, just as you do with `|` and the like. My initial guess for the quotes would be that it would try running everything between them as an executable, although it's an executable and arguments.
Joey