calling multiple batch files from within a batch file

Y

yawnmoth

I have two batch files - hello.cmd and hello2.cmd.

Here's the contents of hello.cmd:

@echo hello, world!

Here's the contents of hello2.cmd:

@hello
@hello

Why is "hello, world!" only output once?
 
S

smlunatick

I have two batch files - hello.cmd and hello2.cmd.

Here's the contents of hello.cmd:

@echo hello, world!

Here's the contents of hello2.cmd:

@hello
@hello

Why is "hello, world!" only output once?

You need to note that any "*.cmd files are Windows Script files and
not batch files (older DOS files.)

The first line "sends" the control over the hello, but there is no
means of return.

Add "call" to before hello

@call "hello"
 
P

Pegasus \(MVP\)

yawnmoth said:
I have two batch files - hello.cmd and hello2.cmd.

Here's the contents of hello.cmd:

@echo hello, world!

Here's the contents of hello2.cmd:

@hello
@hello

Why is "hello, world!" only output once?

.. . . because the first @hello invokes hello.cmd, without
control ever returning to hello2.cmd. Try this instead:

@echo off
call hello
call hello
 
P

Pegasus \(MVP\)

I have two batch files - hello.cmd and hello2.cmd.

Here's the contents of hello.cmd:

@echo hello, world!

Here's the contents of hello2.cmd:

@hello
@hello

Why is "hello, world!" only output once?

You need to note that any "*.cmd files are Windows Script files and
not batch files (older DOS files.)
<snip>
=================

Mhm. What exactly is the difference betwee a "Windows Script File"
and a "Batch File"? I used to think that a "Batch File" is an ASCII
file that contains a number of commands such as copy, md, del. Batch
files have a .bat or a .cmd extension. I'm not so sure about a "Windows
Script File" - the closest that comes to my mind is a "VB Script File",
which is something else again.

Under WinNT,2000,XP and Vista, files with a .cmd extension are
treated in exactly the same way as those with a .bat extension. No
difference there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top