🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.os.msdos.misc
3 messages
3 total messages Started by John Savage Thu, 14 Dec 1995 00:00
overcoming the MSDOS errorlevel problem
#3924
Author: John Savage
Date: Thu, 14 Dec 1995 00:00
19 lines
1608 bytes
Amongst the myriad shortcomings of MSDOS we must include the pair:

  *  FIND does not return an errorlevel to confirm a match
  *  COPY does not copy a file of length 0

Combined, these two can be used to overcome the limitation of no errorlevel
setting. When the output of FIND is redirected to a file, then failure to
match is indicated by the creation of a null file. Any attempt using COPY
to duplicate that file will be unsuccessful whenever the file is of size 0.

type %1 | find "xyz" >tmp1
copy tmp1 tmp0 > \nul
if exist tmp0 echo %1 contained the string xyz

In practice, the above will need to be preceded by: if exist tmp0 del tmp0
and the temporary files subsequently deleted by something like del tmp?
As always, use of a RAM drive for all temporary files is adviseable.
--
John Savage               koala@sydney.dialix.com.au
Re: overcoming the MSDOS errorlevel problem
#3926
Author: Robert B. Clark
Date: Sat, 16 Dec 1995 00:00
52 lines
2809 bytes
John Savage <koala@sydney.dialix.com.au> wrote:

>Amongst the myriad shortcomings of MSDOS we must include the pair:
>
>  *  FIND does not return an errorlevel to confirm a match
>  *  COPY does not copy a file of length 0

Actually, FIND does return an errorlevel in MS-DOS v6 or later:

	0	At least one match was found.
	1	No matches were found.
	2	An error occurred during the search.

If the target audience is running v6+, you can dispense with the COPY
trick altogether, as is shown below:

find "rem " /i < \autoexec.bat > nul
if not errorlevel 1 echo There were REMarked lines in your AUTOEXEC.BAT.

Note: FIND in MS-DOS v5+ includes the /I switch, which performs a
case-insensitive match on the search string.

>type %1 | find "xyz" >tmp1
>copy tmp1 tmp0 > \nul
>if exist tmp0 echo %1 contained the string xyz

Here's a suggestion for a little extra performance.  Under MS-DOS,
copying a zero-byte file actually results in the deletion of the target
file.  So ....

	find "xyz" < %1 > tmp1
	copy /b tmp1+,, > nul
	if exist tmp1 echo %1 contained the string "xyz".
	if exist tmp1 del tmp1 > nul

By copying the semaphore file onto itself, we don't have to delete it if
the test turns out negative, and we don't have to worry about deleting
it beforehand.  Of course, in a small batch like this one the savings
are negligible; however, if this were a long, complicated batch file we
could use an evar to hold the result of the first "if exist" test, and
then simply use that evar throughout in order to avoid extra disk
accesses.

Also, I used redirection instead of a pipe to FIND in order to save a
temp file--a pipe creates two temp files per instance.  Again, this is a
minor point in this example, but could add up to large savings in more
extensive batch programs.


--
Robert B. Clark <rclark@iquest.net>
"Anyone who considers protocol unimportant has never dealt with a cat."  --L. Long
Re: overcoming the MSDOS errorlevel problem
#3918
Author: Ian Staples
Date: Tue, 19 Dec 1995 00:00
17 lines
1295 bytes
John Savage <koala@sydney.dialix.com.au> writes:

>Amongst the myriad shortcomings of MSDOS we must include ... :

>  *  COPY does not copy a file of length 0

Oh, I dunno.  I actually have an application dependent on this
behaviour (and I use XCOPY for all routine copying anyway  :)

Cheers,  Ian S.


-- 

Ian Staples                        E-mail : I.Staples@dpi.qld.gov.au
c/- P.O. Box 1054 MAREEBA          Phone  : +61 (0)70 928 555 Home 924 847
Queensland Australia 4880            Fax  : +61 (0)70 923 593   "   "   "
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads