views:

250

answers:

4

This is a similar question to the one I ask here. I am running on Windows XP.

I am trying to get for loop to work on Windows. Following the suggestion that I have to make sure that the command are valid cmd command, I constructed a valid for loop batch command:

@echo off
FOR /F "tokens=4 delims=," %%G IN ("deposit,$4500,123.4,12-AUG-09") ^
DO ^
echo Date paid %%G ^ 

And put it in a Makefile. This is the content of the makefile:

all:
    @echo off
    FOR /F "tokens=4 delims=," %%G IN ("deposit,$4500,123.4,12-AUG-09") ^
    DO ^
    echo Date paid %%G ^

But still, I got an error:

FOR /F "tokens=4 delims=," %%G IN ("deposit,500,123.4,12-AUG-09") ^ make: * [all] Error 255

Any idea how to fix this?

A: 

your split is wrong, don't use ^. Do as following:

@echo off
FOR /F "tokens=4 delims=," %%G IN ("deposit,$4500,123.4,12-AUG-09") DO  (
    echo Date paid %%G
    rem you can put as many lines as you want here, inside of braces
    echo 123
)
Moisei
I tried your suggestion, but it outputed the exact string `For /F "" .... echo 123)`, not the result.
Ngu Soon Hui
A: 

Maybe you can call your batch command file from the Makefile?

all:
    MyBatch.bat "deposit,$$4500,123.4,12-AUG-09"

With MyBatch.bat as follows.

@echo off
FOR /F "tokens=4 delims=," %%G IN ("%1") ^
DO ^
echo Date paid %%G ^

Beware the $ in the Makefile thought. $ is the escape characher and have to be doubled to get one real $ in strings.

Didier Trosset
Thanks, but I don't think I want to call batch file from my makefile. I would prefer a real makefile windows syntax.
Ngu Soon Hui
A: 

I've found the answer, this is the correct syntax that runs in Makefile Windows:

all:
    @echo off
    FOR /F "tokens=4 delims=," %%G IN ("deposit,$4500,123.4,12-AUG-09") \
    DO   \
    echo Date paid %%G echo 123
Ngu Soon Hui
A: 

I've found that by using && you can do multiple commands inside the for loop like so:

    for %%i in ($(SOMETHING)) do echo %%i 1 && echo %%i 2 && echo %%i 3

This will printout something like:

1 1
2 2
3 3
Valadas