Link to home
Start Free TrialLog in
Avatar of Fraser_Admin
Fraser_AdminFlag for Canada

asked on

using fc with batch file

i have 2 text files called existing.txt and new.txt.  each holds a program version number.

i want to check these files before copying in a new version (ie. if they are the same no copy is needed).  if the version of new < version of existing i don't want to copy in.  i only want new versions greater than existing versions.

i created a vbscript file to give me the version which i send the output to a file.  but the file contains a blank line, then the version number.

how do i compare these two files within a batch the way i need to?
ASKER CERTIFIED SOLUTION
Avatar of SteveGTR
SteveGTR
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Fraser_Admin

ASKER

the text file begins with a blank line then the version will be like
1.1.3 or something like that.

how do i compare if they are equal?
Replace line 8 with this:

if /i "%oldVer%" EQU"%newVer%" echo Old version is equal to the old version

Check this for more information on the if command:

if /?
how do i set a return value in batch

if it is equal or if old > new than I want to return 1 otherwise i want to return 0.

i need to be able to access this value in another batch file.  i just want to call this as a separate one.
if /i "%oldVer%" GTR "%newVer%" exit /B 1

exit /B 0
but how do i access that return value in my calling batch.

also, when i call
exit /B 1
for example, i can't see to get past that in my calling batch.  i put in some echos after that and nothing appears.

i need to be able to get that value of 1 in my calling batch.  i think i can do this with errorlevel right?
That's right. You answered your own question. Once the batch processing hits a exit, the batch is exited as the command says. You'd test %errorlevel% in your calling batch processing to determine the results.
i can't seem to get passed my call to the batch.  i put in an echo as soon as i exit from the batch but it does not come up.
I have this in my called batch
exit /B 1

then in the calling batch right after i have the call to this batch i have echo done and it doesn't get there.  it is like that exit call is telling it to exit from the called and calling batches.
Are you calling the batch file using call?

call yourbatch.bat

If not you won't return.
no just figured that out.  thanks so much for your help!!!
Excellent Response!!