Hi. I'm trying do do batch file for upgrades of couple of DOS machines. What i want is:
if local file (C:\) is the same (date size content?) as file on network (P:\) then continue else replace local file with network file.
this will be repeated for couple of files (autoexec.bat, config.sys, system.ini, etc ...)I'm kinda stuck and can't figure how to do the "are files identical" part.
along these lines, not tested:
@echo off & setlocal
fc c:\dahdah p:\dahdah > nul
if %errorlevel% gtr 0 (
copy /y p:\dahdah c:\dahdah
)
::----- end -----
but looking at it, why not just do a straight copy, after all,
unless files are great-big, who cares?
nbrane, OP is using DOS 6x. No setlocal; no gtr.
fc bla bla > nul
if errorlevel 1 copy bla
=====================================
Helping others achieve escape felicityM2
Yeah, the OP might as well just copy file straight out. After all, FC pulls it over the network, and if you decide to perform the copy, you're pulling the file a second time.
Yes, but a copy should only be made if a copy is needed. If FC works on DOS6.22, I'm with M2 on this one
R2 is right, as usual.FC does a read AND compares the two.
=====================================
Helping others achieve escape felicityM2
Hi. Thanks for replies, i'll try M2 solution tomorrow. Reason why I want to compare files is, because if there are differences (unauthorized modification of local files, or updated files on network) I want to perform restart with correct files.
Hi again.
Well... I'm still stuck.
I did test batch with following content, but can't get errorlevel out of it.test.bat:
FC CONFIG1.SYS CONFIGX.SYS
ECHO KO ERRORLEVEL=%ERRORLEVEL%
IF ERRORLEVEL 1 GOTO DOUPDATE
GOTO NOUPDATE:DOUPDATE
ECHO UPDATE AND RESET
PAUSE
EXIT:NOUPDATE
ECHO NOUPDATE
PAUSEresults into:
.....
0000039E: 68 0D
0000039F: 6C 0A
FC: CONFIG1.SYS longer than CONFIGX.SYSKO ERRORLEVEL=
NOUPDATE
Press any key to continue . . .
"ECHO KO ERRORLEVEL=%ERRORLEVEL%" I don't know why that line fails to put out a number.
Maybe post the rest of the bat.
=====================================
Helping others achieve escape felicityM2
It's whole bat (only first row is missing "ECHO OFF" ).
I'm testing it in Vmware virtual machine, i'll try it on real machine tomorrow.
FC CONFIG1.SYS CONFIGX.SYS
ECHO KO ERRORLEVEL=%ERRORLEVEL%
IF ERRORLEVEL 1 GOTO DOUPDATEYou are checking the errorlevel of ECHO, not the errorlevel of FC
Errorlevel-checking can only be done on the last command executed
old dos won't echo a %errorlevel%, only respond to it.
quite retarded, in my book. even the friggin response is limited to "greater than", so you have to do a lot of sucky testing to make sure you got it right.
@tvc, good point too: always grab errorlevel immediately or it will be disrupted by the next command.
so. I did the test on real HW and result is same as in VMware. I made another test bat, but again - not working...
tets2.bat results into 0000
ECHO OFFFC CONFIG1.SYS CONFIGX.SYS
IF ERRORLEVEL 5 GOTO 5555
IF ERRORLEVEL 4 GOTO 4444
IF ERRORLEVEL 3 GOTO 3333
IF ERRORLEVEL 2 GOTO 2222
IF ERRORLEVEL 1 GOTO 1111
IF ERRORLEVEL 0 GOTO 0000:5555
echo 5555
goto blargh:4444
echo 4444
goto blargh:3333
echo 3333
goto blargh:2222
echo 2222
goto blargh:1111
echo 1111
goto blargh:0000
echo 0000
goto blargh:blargh
PAUSEalso this one is not working:
::EL.BAT v2.15 (283 bytes)
::Displays errorlevel set by last program run
::by: Vernon Frazee 12/94 - Last mod: 03/97
::http://www.vfrazee.com
@echo offFC CONFIG1.SYS CONFIGX.SYS
set a=Errorlevel|set b=|set c=for %%_ in (0 1 2
%c%) do if %a% %%_00 set d=%%_
if not %a% 200 set b=6 7 8 9
%c% 3 4 5 %b%) do if %a% %d%%%_0 set d=%d%%%_
if not %a% 250 set b=6 7 8 9
%c% 3 4 5 %b%) do if %a% %d%%%_ set d=%d%%%_
set a=|set b=|set c=|set d=|echo %d%
I didn't find edit button so here is next post ...
EDIT: omg I'm blind found it now .... I have been probably thinking about solution too much :)I can get errorlevel 1 this way "fc configx.sys" (FC: Insufficient number of file specifications) so errorlevels do work.
maybe under DOS it should return 0 even if files are different?
but then I also need to do the check differently.so finally this seems to be working
@echo offFC CONFIG1.SYS CONFIGX.SYS > err.txt
FIND "no" err.txt
IF ERRORLEVEL 1 GOTO DOUPDATE
GOTO NOUPDATE:DOUPDATE
ECHO UPDATE AND RESET
PAUSE:NOUPDATE
ECHO NOUPDATE
PAUSE
maybe try to boil it down to bare nails. do something really "dumb" to kick error, then see what hapns:
@echo off & setlocal
type fartblog.yek
if errorlevel 1 echo levelone
if errorlevel 2 echo leveltwo?
if errorlevel 0 echo you actually have a file called fartblob.yek?
::----
then, assuming you don't, you should see "levelone".
then run your fc and immediately discharge the errorlevel (and, make SURE the confits are, indeed, different!):
fc config.sys configx.sys
if errorlevel 1 goto lev1
if errorlevel 0 goto lev0
:lev1
echo different
goto :xit
:lev0
echo same
:xit
::------ ooops!! damn!! sorry
you are indeed correct, i made a trip to the dungeon to check the dinosaur, and fc did not report the errorlevel on a file mismatch. good idea using the find!
Of course, when checking errorlevel, the first question you should ask yourself is, do you KNOW that this command/script returns an exitcode ? Then, WHAT exitcodes does it return for what cases ?
I'm going to boot in DOS and check.
=====================================
Helping others achieve escape felicityM2
You're right; NG in DOS. It's a bit disconcerting to realize how limited DOS is.
But refreshing to get a snappy interface, after using CMD prompt, which is like jogging in wet cement.
=====================================
Helping others achieve escape felicityM2
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |