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
精彩评论