Calling a dos batch file from python

Discussion in 'Python' started by n o s p a m p l e a s e, Sep 4, 2007.

  1. 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
     
    n o s p a m p l e a s e, Sep 4, 2007
    #1
    1. Advertising

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

    Guest

    On Sep 4, 8:42 am, n o s p a m p l e a s e <>
    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, 2007
    #2
    1. Advertising

  3. On Sep 4, 5:01 pm, wrote:
    > On Sep 4, 8:42 am, n o s p a m p l e a s e <>
    > 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
     
    n o s p a m p l e a s e, Sep 5, 2007
    #3
  4. 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 <> wrote:
    > On Sep 4, 5:01 pm, wrote:
    > > On Sep 4, 8:42 am, n o s p a m p l e a s e <>
    > > 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
    >
     
    Wesley Brooks, Sep 5, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Kraft

    running dos batch file

    John Kraft, Feb 3, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    648
    Brian W
    Feb 3, 2004
  2. DB
    Replies:
    2
    Views:
    1,437
    Eliyahu Goldin
    Jun 22, 2005
  3. Replies:
    2
    Views:
    447
    Toby A Inkster
    Jan 16, 2004
  4. Alan
    Replies:
    8
    Views:
    699
    rossum
    Jun 24, 2005
  5. =?Utf-8?B?bWF0bHlu?=

    creating a file within a subdir in DOS batch file

    =?Utf-8?B?bWF0bHlu?=, Sep 20, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    672
    =?Utf-8?B?bWF0bHlu?=
    Sep 20, 2007
Loading...

Share This Page