469,647 Members | 1,800 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,647 developers. It's quick & easy.

Run batch files in Windows XP

Hi,

I'm a newbie and I was wondering if anyone knew a (Python) script to
run 4 batch files, one after the other (assuming the directories are
known). It would be better if all 4 batch files could run
simultaneously, but that might break Windows... ;) The problem I had
was I couldn't get the files to RUN, only to OPEN. Thanks for the
help!!!

pseudo-code looks like this
Get directory Run batch1
Run batch2
Run batch3
Run batch4


Jul 25 '05 #1
7 8829
er*******@gmail.com wrote:
I'm a newbie and I was wondering if anyone knew a (Python) script to
run 4 batch files, one after the other (assuming the directories are
known). It would be better if all 4 batch files could run
simultaneously, but that might break Windows... ;) The problem I had
was I couldn't get the files to RUN, only to OPEN. Thanks for the
help!!!


You shouldn't need a Python program for that.

To run the not simultaneously:

call batch1.bat
call batch2.bat
call batch3.bat
call batch4.bat

Put those commands with appropriate names in a fifth batch file and
execute that and it will work.

To run them simultaneously (which won't break Windows, but might not do
what you would like, depending on what those batch files actually do),
just add the "start" command into the equation. You can get help on the
start command using "start /?" at a DOS prompt.

-Peter
Jul 25 '05 #2
Thanks Peter.
The issue is I haven't done very much batch programming. I need to
prompt the user for input and each batch file is in a different
directory. How do I change directories and prompt for user input?
Thanks!

Jul 25 '05 #3
Ernesto wrote:
The issue is I haven't done very much batch programming. I need to
prompt the user for input and each batch file is in a different
directory. How do I change directories and prompt for user input?


Ah, now you're talking things where Python, while not strictly required,
can start to make things easier. :-)

To run external things like batch files, you import the "os" module and
use the system() function:

import os
os.system('somebatchfile.bat')

Since you're prompting the user for input first, presumably the input is
passed to the batch file in some way, like so:

input = raw_input('Enter your incredibly useful info now:')

("raw_input" is a builtin... good to learn about as many of those as you
can handle by reading the docs here:
http://docs.python.org/lib/built-in-funcs.html . Some of those are
absolutely not important to you at this early stage, others are.)

Then with the input you've collected, you could pass it to the batch
file like so:

os.system('myfile.bat %s' % input)

The %s and % together result in whatever text the user entered being
added on the command line for the call to myfile.bat, exactly as though
it had been executed manually with the same input.

-Peter
Jul 25 '05 #4
Thanks.

Yeah I started to write in Python. Looks like this:

************************************************** ****
import os
from os.path import join

# Get input from user and make sure it is valid

fileDirec = raw_input("\nEnter the path of where your
STMP3XXX_SDK_FIRMWARE\nis located (i.e. C:\) : ")
if not os.path.exists(fileDirec):
exit(" ** File or path does not exist... exiting ** ")
# Builds all binaries simultaneously for SDK 3.050
def buildBinaries(_path):
_bootmanagerPath = join(_path,
"STMP3XXX_SDK_FIRMWARE\DeviceDriver\Media\SmartMed ia\BootManager\STMP3500\make")
_usbmscPath = join(_path,
"STMP3XXX_SDK_FIRMWARE\Projects\Sdk\lcdexample\usb msc\make")
_playerPath = join(_path,
"STMP3XXX_SDK_FIRMWARE\Projects\Sdk\lcdexample\pla yer\make")
_mtpPath = join(_path,
"STMP3XXX_SDK_FIRMWARE\Projects\Sdk\lcdexample\mtp \make")

# First build bootmanager...change to that directory
# and run the bootmanager file... Similarly for the others...
os.chdir(_bootmanagerPath)
os.execl(("bootmanager.bat"),("BOOTMANAGER ALL"))

os.chdir(_usbmscPath)
os.execl(("usbmsc.bat"),("USBMSC ALL UPDATER"))

os.chdir(_playerPath)
os.execl(("player.bat"),("PLAYER ALL"))

os.chdir(_mtpPath)
os.execl(("mtp.bat"),("MTP ALL"))

# After gathering user input, call routine to build binaries...
buildBinaries(fileDirec)
************************************************** ****************

The issue is after the first execution of os.execl, the script stops
altogether. In other words after bootmanager.bat executes, its over.
I would love to Python if I could get all scripts to execute (executing
simultaneously would be a major + !)
I'll try os.system
THANKS!!!

Jul 25 '05 #5
Looks like I'm not getting my parameters to my batch file correctly.
I'm using os.system like this:
os.system('bootmanager.bat %s' %"BOOTMANAGER ALL")

where 'BOOTMANAGER ALL' is what I type at the command prompt arguments.
That must not be right?

Jul 25 '05 #6
Ernesto wrote:
Looks like I'm not getting my parameters to my batch file correctly.
I'm using os.system like this:
os.system('bootmanager.bat %s' %"BOOTMANAGER ALL")

where 'BOOTMANAGER ALL' is what I type at the command prompt arguments.
That must not be right?


The batch file will see two parameters (in %1 and %2) if that's not what
you want, put double quotes around the %s, like so:

os.system('bootmanager.bat "%s"' % "BOOTMANAGER ALL")
--
Benji York

Jul 25 '05 #7
On 25 Jul 2005 12:57:23 -0700, "Ernesto" <er*******@gmail.com> declaimed
the following in comp.lang.python:
Looks like I'm not getting my parameters to my batch file correctly.
I'm using os.system like this:
os.system('bootmanager.bat %s' %"BOOTMANAGER ALL")

where 'BOOTMANAGER ALL' is what I type at the command prompt arguments.
That must not be right?
Is there a possibility you have too much specified there...

What do you really type at a command prompt? The above code is
the equivalent of

C:\>bootmanager.bat BOOTMANAGER ALL

where C:\ is the prompt string.

-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.netcom.com/> <

Jul 26 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Charles Neitzel | last post: by
3 posts views Thread by emman_54 | last post: by
4 posts views Thread by MLH | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.