Tags: bat, batch, call, calling, dos, file, itfrom, mybatch, programming, python, run, script, suppose

Calling a dos batch file from python

On Programmer » Python

1,882 words with 3 Comments; publish: Mon, 28 Apr 2008 02:44:00 GMT; (20078.13, « »)

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

All Comments

Leave a comment...

  • 3 Comments
    • On Sep 4, 8:42 am, n o s p a m p l e a s e <nospam.ple....python.todaysummary.com.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

      #1; Mon, 28 Apr 2008 02:46:00 GMT
    • On Sep 4, 5:01 pm, kyoso....python.todaysummary.com.gmail.com wrote:

      > On Sep 4, 8:42 am, n o s p a m p l e a s e <nospam.ple....python.todaysummary.com.alum.com>

      > wrote:

      >

      >

      > The subprocess module should work.

      >

      Thanx to all those who responded. It was quite simple.

      import os

      os.system("mybatch.bat")

      NSP

      #2; Mon, 28 Apr 2008 02:47:00 GMT
    • 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 <nospam.please.python.todaysummary.com.alum.com> wrote:

      > On Sep 4, 5:01 pm, kyoso....python.todaysummary.com.gmail.com wrote:

      > 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

      >

      #3; Mon, 28 Apr 2008 02:48:00 GMT