[comp.sys.ibm.pc] .bat files within extra command.com

epb19@uiucuxe.CSO.UIUC.EDU (11/04/86)

I am looking for someone who has experience in writing .bat files which run
from within other .bat  files, expeciallly on systems in which certain programs
require the reloading of command.com after running the program.  I know it is
possible to load the second command.com, and that it takes up extra RAM.
What I am looking for is a group of examples of how you have worked out ways
to do this, and which ways are easiest, fastest, least RAM intensive, etc.

Hoping to thank you soon for your time and consideration.

P.S.  I could use .bat files from 2.1, 2.11, 3.0, 3.1 and 3.2  *thanks*

karamich@uiucuxc.CSO.UIUC.EDU (11/05/86)

  It would help to know exactly what you would like to do, before i start
  giving you hints as to how "to do .bat files".  I have had the experience
  many times where an unexperienced user makes a simple problem quite
  complex by offering me "their solution" to the problem.  What you want
  to do might be more easily done, using another technique.

tom karamichos
University of Illinois at Urbana-Champaign
Computing Services Office - PC Consulting Dept.

BITNET:	karamich@uiucuxc.bitnet
ARPA:	karamich@uiucuxc.cso.uiuc.edu
CSNET:	karamich@uiucuxc.csnet
UUCP:	{ihnp4,pur-ee,convex}!uiucdcs!uiucuxc!karamich

-------------------------------------------------------------
 Women -- you can't live without them, you can't shoot them!
-------------------------------------------------------------

jkg@gitpyr.gatech.EDU (Jim Greenlee) (11/16/86)

In article <10300005@uiucuxe> epb19@uiucuxe.CSO.UIUC.EDU writes:
>
>I am looking for someone who has experience in writing .bat files which run
>from within other .bat  files, expeciallly on systems in which certain programs
>require the reloading of command.com after running the program.  I know it is
>possible to load the second command.com, and that it takes up extra RAM.
>What I am looking for is a group of examples of how you have worked out ways
>to do this, and which ways are easiest, fastest, least RAM intensive, etc.
>

The ordinary way to do this is to pass the name of the batch file as a 
parameter to COMMAND.COM. Also, COMMAND.COM must be invoked with the /C 
option so that it will go away after the batch file terminates.

As an example, suppose you want to run the file FOO.BAT from within the
file BIGFOO.BAT. You use the following to cause control to be returned to
BIGFOO after FOO completes:

		.
		.
	  [some commands]
		.
		.
	  COMMAND/C FOO
		.
		.
	  [more commands]
		.
		.

I have used this trick numerous times and it works. You can also do nested
FOR statements the same way like this:

FOR %%I IN (...) DO COMMAND/C FOR %%J IN (...) DO MYPROG

or to execute a batch file:

FOR %%I IN (...) DO COMMAND/C FOR %%J IN (...) DO COMMAND/C FOO

Each invocation of the command processor will take up a little more memory,
but as long as all applications remember to pop their copy "off the stack",
so to speak, you shouldn't have any problems.

Of course, for this to work properly, you must have a copy of COMMAND.COM
on the disk where the batch file is (for a floppy-based system) or it must 
be found in your current PATH (for a hard disk system).

                                             Jim Greenlee
-- 
The Shadow...!{akgua,allegra,amd,hplabs,ihnp4,seismo,ut-ngp}!gatech!gitpyr!jkg

Abj lbh'ir tbar naq qbar vg! Whfg unq gb xrrc svqqyvat jvgu vg hagvy lbh
oebxr vg, qvqa'g lbh?!

rosen@mtgzz.UUCP (11/26/86)

In article <2643@gitpyr.gatech.EDU>, jkg@gitpyr.gatech.EDU (Jim Greenlee) writes:
> In article <10300005@uiucuxe> epb19@uiucuxe.CSO.UIUC.EDU writes:
> >
> >I am looking for someone who has experience in writing .bat files which run
> >from within other .bat  files, [....]

> The ordinary way to do this is to pass the name of the batch file as a 
> parameter to COMMAND.COM. Also, COMMAND.COM must be invoked with the /C 
> option so that it will go away after the batch file terminates.
 [...]

I don't get it, what's all the fuss? 
Why do you need to invoke COMMAND at all. In my
experience you can just enter the second .BAT file as an ordinary
commmand ???

jkg@gitpyr.UUCP (11/27/86)

In article <2295@mtgzz.UUCP> rosen@mtgzz.UUCP writes:
>> The ordinary way to do this is to pass the name of the batch file as a 
>> parameter to COMMAND.COM. Also, COMMAND.COM must be invoked with the /C 
>> option so that it will go away after the batch file terminates.
> [...]
>
>Why do you need to invoke COMMAND at all. In my
>experience you can just enter the second .BAT file as an ordinary
>commmand ???

You don't as long as you don't mind not being able to return to the calling
batch file. Invoking a batch file directly from within a batch file will 
cause control to be passed (just like you want) but as soon as the second
batch file terminates, you get dropped back into DOS.

The original poster wanted to invoke the second batch file as sort of a sub-
routine to the first, with the ability to return control to the calling batch 
file after the called batch file terminated. As far as I know, the only way 
to do this is by invoking a second command processor with the name of the 
called batch file passed as an argument. The /C option tells COMMAND.COM
to "terminate and don't stay resident" after the called batch file executes.

                                               Jim Greenlee


-- 
The Shadow...!{akgua,allegra,amd,hplabs,ihnp4,seismo,ut-ngp}!gatech!gitpyr!jkg

Jryy, abj lbh'ir tbar naq qbar vg! Whfg unq gb xrrc svqqyvat jvgu vg hagvy lbh
oebxr vg, qvqa'g lbh?!

nather@ut-sally.UUCP (11/27/86)

> > >I am looking for someone who has experience in writing .bat files which run
> > >from within other .bat  files, [....]
>
> I don't get it, what's all the fuss? 
> Why do you need to invoke COMMAND at all. In my
> experience you can just enter the second .BAT file as an ordinary
> commmand ???

If you do it that way control never returns to the original .bat file.
It's fine if that's what you intend (chaining) but if you want the second
.bat file to behave like a subroutine you must use "command /c batfile" or
it won't return control.

-- 
Ed Nather
Astronomy Dept, U of Texas @ Austin
{allegra,ihnp4}!{noao,ut-sally}!utastro!nather
nather@astro.AS.UTEXAS.EDU

reintom@rocky2.UUCP (Tom Reingold) (11/28/86)

[]
>>>I am looking for someone who has experience in writing .bat files which run
>>>from within other .bat  files, [....]
> 
>>The ordinary way to do this is to pass the name of the batch file as a 
>>parameter to COMMAND.COM. Also, COMMAND.COM must be invoked with the /C 
>>option so that it will go away after the batch file terminates.
>[...]
>
>I don't get it, what's all the fuss? 
>Why do you need to invoke COMMAND at all. In my
>experience you can just enter the second .BAT file as an ordinary
>commmand ???

That only works when the second batch file is the last command in
the first batch file.  What you don't realize is that the second
batch file would not return to the first.  This is because memory
for batch files, according to my observations (not informed
knowledge), is overlayed and not chained.  It's unfortunate and
stupid but can be overcome with the "command /c batchfilename"
solution.

.
.
.
.
.
.
.
.

-- 
########################################################################
Tom Reingold -- Rockefeller Univ, 1230 York Av, NY 10021; (212) 570-7709
UUCP:       {seismo|philabs|phri|harvard|ihnp4}!cmcl2!rna!rocky2!reintom
ARPANET: reintom@rockefeller.arpa <<<<<<<->>>>>> BITNET: REINTOM@ROCKVAX