Re: Problems calling batch files (*.bat) from Python???

Discussion in 'Python' started by Algirdas Brazas, Aug 23, 2008.

  1. I haven't tested Your code, so can't tell You why it is working as You say. But
    to open batch file in my script I use simple:

    subprocess.Popen("c:\VerrLongPath\AnotherPath\mybatch.bat"").communicate()

    You can also play with pipes for Popen...

    Algirdas Brazas

    ----- Original Message -----
    From: Marian Popa
    To:
    Sent: Saturday, August 23, 2008 4:29 PM
    Subject: Problems calling batch files (*.bat) from Python???


    Hello,

    I am new in Python programming and I have the following problem:
    I have a script in which I need to open an application (called from a batch
    file - "trace.bat"). For this purpuse, I'm executing the following piece of
    code:

    import os, win32process
    from win32api import Sleep

    os.chdir("D:\\Marian\\Proiecte\\AMT\\Trace")
    os.startfile("launch_trace.bat")
    #subprocess.call("D:\\Marian\\Proiecte\\AMT\\Trace\\trace.bat")
    #pr = win32process.CreateProcess(None,
    "D:\\Marian\\Proiecte\\AMT\\Trace\\trace.bat", None, None, 0,
    win32process.NORMAL_PRIORITY_CLASS, None, None, win32process.STARTUPINFO())

    .....
    .....
    .....
    .....

    But, when I call the "os.startfile("launch_trace.bat")" command, the program
    prompter appears, but the program called in the batch file is opened ONLY after
    the whole script has finished the execution.
    Unfortunatley, after this line there are some very important things that has to
    be executed in the right order. I mean, the execution of the batch file is
    important for the rest of the code.
    What is strange is that if I execute this code step-by-step, using the debugger,
    or if I put a breakpoint on the "launch_trace" line and then I step on it,
    everything is working fine - the Trace application is launced correctly.
    Could anyone help in this direction? I need to launch the application and after
    this I want to continue the execution of the script.

    Thank you in advance!

    P.S. I've also tried with processes (see the commented lines) and I get the same
    problems; for MSWord application, the behavior is the same - it is launched
    after the script ends. Also, I have to mention that I don't have a DLL of this
    application and it is not a COM application in order to control it from Python.

    Marian





    --
    http://mail.python.org/mailman/listinfo/python-list
     
    Algirdas Brazas, Aug 23, 2008
    #1
    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. Joe
    Replies:
    1
    Views:
    367
    Victor Bazarov
    May 22, 2007
  2. n o s p a m p l e a s e

    Calling a dos batch file from python

    n o s p a m p l e a s e, Sep 4, 2007, in forum: Python
    Replies:
    3
    Views:
    1,237
    Wesley Brooks
    Sep 5, 2007
  3. Chris Rebert

    Re: Converting .py files to batch files.

    Chris Rebert, Sep 15, 2008, in forum: Python
    Replies:
    0
    Views:
    384
    Chris Rebert
    Sep 15, 2008
  4. Alessandro
    Replies:
    6
    Views:
    2,254
    Arne Vajhøj
    Mar 4, 2009
  5. John Reed
    Replies:
    1
    Views:
    122
    Andreas Schwarz
    Mar 7, 2004
Loading...

Share This Page