开发者

how can I pass a parameter I read from a file in a batch file to a program call in the same batch file?

In my batch program can sucessf开发者_开发问答ully read from a file like this:

for /f %%a in (crc.txt) do (
@echo CRC read in from file is %%a now
)

where %%a is printed out as being 0xCD0134DE

Now i want to pass in %%a into a C program call in the same batch file:

../myprogram %%a

Problem is myprogram interprets the %%a argument as being '%a' (I know this as I print out the argument as soon as myprogram starts. I've tried

../myprogram %a         //program thinks the argument is 'a'
../myprogram a          //program thinks the argument is 'a'

ie I don't get the value of 0xCD0134DE as being passed in.


Try this:

for /f %%a in (crc.txt) do (
    @echo CRC read in from file is %%a now
    ../myprogram %%a
)

%%a is only in scope for the for loop. If you need to use value this throughout the script, then set a local environment variable to hold the value:

for /f %%a in (crc.txt) do (
    set CRC=%%a
)
@echo CRC read in from file is %CRC% now
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜