Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: using one batch file as a command in another  (Read 3615 times)

0 Members and 1 Guest are viewing this topic.

Jono

  • Guest
using one batch file as a command in another
« on: June 22, 2004, 10:04:16 PM »
I've only just started using batch files and I think I've gotten a little to tricky for myself.

I created a batch file in which to dump the filenames  after a replace command so that the file looks like this:

replacing G:\filename1
replacing G:\filename2

etc...

I then created a new batch batch file to move the newly replaced files to another directory for a short time:

move %1 G:\directory1\

I named this second batch file "replacing.bat" so that when I ran the first one, it saw "replacing" as a command and the file as the variable.

Now to my delight, this worked perfectly for the first file, but to my disappointment, the first file is all that it did.

It seems that after running the replacing command the first time, control is not returned back to the first batch file so that the second line can be run.

Does anybody know why this would happen and how I can fix it?

Thanks in advance,
Jono


MalikTous

  • Guest
Re: using one batch file as a command in another
« Reply #1 on: July 15, 2004, 06:19:16 PM »
Use the command CALL before each nested batch file, so it opens in its own command shell before it executes, then returns to the controlling file.

Or you can make the routines you want to use subroutines in the main batch files and use GOTO or GOSUB and RETURN or an if-then or for-in-do to run it. This latter is a bit more stable than CALL but requires that you do some actual programming.

Kim

  • Guest
Re: using one batch file as a command in another
« Reply #2 on: July 26, 2004, 09:31:28 AM »
 ??? I need to call a couple of batch files from within the one file.  The first one starts JBoss which doesn't actually "end".  My problem is that even when I use the CALL command to call the batch file to start JBoss, it starts in the same window and hence never reaches the rest of the initialising batch file.  I'm completely flumoxxed (sp?) here.  Any help would be appreciated.    :o  Please email me if you have any ideas at [email protected]

Thanks
Kim

MalikTous

  • Guest
Re: using one batch file as a command in another
« Reply #3 on: July 26, 2004, 08:46:34 PM »
Nesting batch files has always been a problem since Windows started. The batch processor has always been a single-thread function. CALL runs a second batch file in a separate COMMAND.COM shell, but doesn't return control to the first until the second file exits.

Using a subroutine will show similar behaviour. GOSUB to a section with a copy of JBOSS content will still hang the instruction pointer in the subroutine until the JBOSS file continues and reaches the RETURN statement.

Best option here is either to do all the setup before running JBOSS as a subroutine, or to do a setup batch file, then hand off to JBOSS, which itself has a handoff to a cleanup routine. (A handoff is simply making the last line of a batch file another batch file.)

You may also get better results by replacing COMMAND.COM with JP Software's 4DOS command shell.