Solved

using fc with batch file

Posted on 2007-12-05
12
1,939 Views
Last Modified: 2010-04-21
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?
0
Comment
Question by:Fraser_Admin
  • 7
  • 5
12 Comments
 
LVL 30

Accepted Solution

by:
SteveGTR earned 500 total points
ID: 20414267
Depends on how the version information is formatted in the output files you mentioned.

You could do something like this. You'd format the names of the files as the 2nd parameter to the GETVER calls.
@echo off
 
setlocal
 
call :GETVER oldVer "oldver.txt"
call :GETVER newVer "newver.txt"
 
if /i "%oldVer%" GTR "%newVer%" echo Old version is newer than old version
 
goto :EOF
 
:GETVER
 
set %~1=
 
for /f "tokens=*" %%a in ('type "%~2" 2^>NUL') do set %~1=%%a
 
goto :EOF

Open in new window

0
 

Author Comment

by:Fraser_Admin
ID: 20414571
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?
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 20414585
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 /?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:Fraser_Admin
ID: 20414732
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.
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 20414826
if /i "%oldVer%" GTR "%newVer%" exit /B 1

exit /B 0
0
 

Author Comment

by:Fraser_Admin
ID: 20414857
but how do i access that return value in my calling batch.

0
 

Author Comment

by:Fraser_Admin
ID: 20414956
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?
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 20414983
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.
0
 

Author Comment

by:Fraser_Admin
ID: 20415038
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.
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 20415080
Are you calling the batch file using call?

call yourbatch.bat

If not you won't return.
0
 

Author Comment

by:Fraser_Admin
ID: 20415319
no just figured that out.  thanks so much for your help!!!
0
 

Author Closing Comment

by:Fraser_Admin
ID: 31412939
Excellent Response!!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
The viewer will learn how to count occurrences of each item in an array.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now