471,348 Members | 1,439 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

Calling a dos batch file from python

Suppose I have a batch file called mybatch.bat and I want to run it
from a python script. How can I call this batch file in python script?

Thanx/NSP

Sep 4 '07 #1
3 16191
On Sep 4, 8:42 am, n o s p a m p l e a s e <nospam.ple...@alum.com>
wrote:
Suppose I have a batch file called mybatch.bat and I want to run it
from a python script. How can I call this batch file in python script?

Thanx/NSP
The subprocess module should work.

Mike

Sep 4 '07 #2
On Sep 4, 5:01 pm, kyoso...@gmail.com wrote:
On Sep 4, 8:42 am, n o s p a m p l e a s e <nospam.ple...@alum.com>
wrote:
Suppose I have a batch file called mybatch.bat and I want to run it
from a python script. How can I call this batch file in python script?
Thanx/NSP

The subprocess module should work.
Thanx to all those who responded. It was quite simple.

import os
os.system("mybatch.bat")

NSP

Sep 5 '07 #3
I looked into this a little while ago so I could get the MAC address
of a machine while on linux or windows. Here's a simplified version
that just does the windows side;

self.macMatch = re.compile(r"((\w\w[:-]){5}\w\w)")
data = os.popen("ipconfig /all", 'r')
text = data.read()
tup = self.macMatch.search(text).span()
mac = text[tup[0]:tup[1]].replace('-',':')
return mac

This method allows you to catch the text which would normally be
output to the dos window.

Cheers,

Wes.

On 05/09/07, n o s p a m p l e a s e <no***********@alum.comwrote:
On Sep 4, 5:01 pm, kyoso...@gmail.com wrote:
On Sep 4, 8:42 am, n o s p a m p l e a s e <nospam.ple...@alum.com>
wrote:
Suppose I have a batch file called mybatch.bat and I want to run it
from a python script. How can I call this batch file in python script?
Thanx/NSP
The subprocess module should work.
Thanx to all those who responded. It was quite simple.

import os
os.system("mybatch.bat")

NSP

--
http://mail.python.org/mailman/listinfo/python-list
Sep 5 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.