views:

240

answers:

2

I have a build.bat file which uses %1 internally... so you might call:

build 1.23

I wanted it to read the parameter from a separate file, so I tried putting "1.23" in version.txt and doing:

build < version.txt

But it doesn't work. Isn't this how piping works? Is what I want possible and if so how?

A: 

I think it would make more sense if you handle the file processing within the batch file on the off chance that version.txt is not edited correctly.

You should modify your script to parse the file to get the version if the .bat file is executed as:

     build FILE version.txt
David Relihan
I don't understand what the second half of your answer means
John
I mean just the change the start of your .bat file that handle the command line arguments to parse the file version.txt if the .bat script is executed like that. In my opinion, that would get what you want while maintaining clarity
David Relihan
+1  A: 

The FOR command in DOS has a form which parses files and assigns the tokens it finds to variables, which can then be used as arguments to other batch files. Assuming version.txt contains the single line "1.23", this batch file will open it, assign 1.23 to the variable, then call your original batch file, passing the variable's value as a command-line argument.

@echo off
for /f %%i in (version.txt) do call build.bat %%i

If version.txt contains more than one line, build.bat is called once for each line. Type help for at a DOS prompt to see what other features you might be able to use.

shambulator