开发者

Makefile For Loop on Windows

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 su开发者_C百科re 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?


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


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


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
)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜