🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #1331

Re: Another MsDos batch programming challenge

#1331
From: Yossi Gil
Date: Mon, 07 Sep 1992 16:30
72 lines
3208 bytes
cctr132@csc.canterbury.ac.nz (Nick FitzGerald, CSC, Uni. of Canterbury, NZ) writes:

>In article <1992Sep4.213842.14734@mits.mdata.fi>, kennu@mits.mdata.fi
>(Kenneth Falck) writes:
>> In article <1992Sep4.032836.7299@cs.ubc.ca> yogi@cs.ubc.ca (Yossi Gil)
>writes:
>>>Yes, I tested it. It works. It relies on the way DOS does batch file:
>>>	
>>>	1. Open file.
>>>	2. Seek in file to current statement. 
>>>	3. Interpret statement. 
>>>	4. Close file.
>>>	5. Execute statement
>>>	6. Goto 1 if not done.
>>>
>>>This is why Batch Programming is so inefficient.

>I missed Yossi's original post on this, so apologies if he covered some
>of the following.

No, I didn't. I was just trying to give a rough idea on what's going
on. I hope that Timo will care enough to include your observations. 

>The actual DOS batch processor is a tad more involved than Yossi's
>outline suggests.  Whilst the following may not seem much different from
>what Yossi suggests, some subtle implications of batch processor
>operations are more clearly apparent from it.  To the best of my ability
>to tell, the following is a more accurate outline:

> 1.  Open file
> 2.  Read first line
> 3.  Note number of -chars- read thus far
> 4.  Parse line (for redirection, etc)
> 5.  Close file
> 6.  Execute command
> 7.  Open file
> 8.  Read to number of chars recorded in 4.
> 9.  Read to next EOL or EOF
>10.  If command is null and EOF goto 12.
>11.  Loop to 3.
>12.  Close file
....

>Copy the following batch files to a suitable directory.  Make a backup
>copy of BATTEST.BAT (say BATTEST1.BAT ).

>-----------------------  BATTEST.BAT  -----------------------
>echo off
>echo Batch test 1
>copy battest2.bat battest.bat
>echo Batch test 1

>-----------------------  BATTEST2.BAT  -----------------------
>echo off
>echo Batch test 2
>copy battest2.bat battest.bat  dir
>echo Batch test 2

>NOTE:  The "dir" on line 3 of BATTEST2.BAT is preceded by -TWO- spaces. 
>It is most important that both are included (but more won't hurt  8-) ).

>Change to the directory where these batches are, and execute BATTEST. 
>Your output should look something like:
....

I guess the above example could be used to generate more robust
self modifying batch files.
--
Joseph (Yossi) Gil                 {alberta,uw-beaver,uunet}!ubc-cs!yogi
Dept. of Computer Science          yogi@cs.ubc.ca (cs.ubc.ca=137.82.8.5)
6356 Agricultural Road., Univ. of B.C.,             Tel: +1-604-822-8175
Vancouver, British Columbia, V6T 1Z2, Canada.       Fax: +1-604-822-5485
Technical Details
Message-ID: <1992Sep7.163052.26033@cs.ubc.ca>
Path: arc1-ca.pugleaf.net!sparky!uunet!sun-barr!cs.utexas.edu!usc!wupost!gumby!destroyer!ubc-cs!yogi
References: <israel.715477510@unixg.ubc.ca> <1992Sep3.214401.5000@uwasa.fi> <1992Sep4.032836.7299@cs.ubc.ca> <1992Sep4.213842.14734@mits.mdata.fi> <1992Sep7.211129.702@csc.canterbury.ac.nz>

Show Full Headers
Complete Article Headers
Newsgroups: comp.os.msdos.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!sun-barr!cs.utexas.edu!usc!wupost!gumby!destroyer!ubc-cs!yogi
From: yogi@cs.ubc.ca (Yossi Gil)
Subject: Re: Another MsDos batch programming challenge
Message-ID: <1992Sep7.163052.26033@cs.ubc.ca>
Sender: usenet@cs.ubc.ca (Usenet News)
Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
References: <israel.715477510@unixg.ubc.ca> <1992Sep3.214401.5000@uwasa.fi>   <1992Sep4.032836.7299@cs.ubc.ca> <1992Sep4.213842.14734@mits.mdata.fi> <1992Sep7.211129.702@csc.canterbury.ac.nz>
Date: Mon, 7 Sep 92 16:30:52 GMT
Lines: 72