Calling a dos batch file from python

  • Thread starter n o s p a m p l e a s e
  • Start date
N

n o s p a m p l e a s e

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
 
K

kyosohma

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
 
W

Wesley Brooks

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.
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top