Question: How to execute an EXE with Python?

Fausto Arinos de A. Barbuto fbarbuto at
Tue Aug 27 22:41:09 CEST 2002

Hi Walt,

    Amazing, that doesn't work either. I get the following
    message instead:

Traceback (most recent call last):
  File "C:\PROGRA~1\PYTHON\lib\site-packages\Pythonwin\pywin\framework\", line
301, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\Fausto\Execs\", line 4, in ?

  File "C:\PROGRAM FILES\PYTHON\lib\", line 266, in execl
    execv(file, args)
OSError: [Errno 2] No such file or directory

    Naturally, as I am a Windows ME user, I have to make a
    few changes to the code you suggest. My script then became:

    import os
    myPy = 'c:/fausto/execs/teste.exe'
    os.execl('c:/windows/', '/k', myPy)

    But nothing but the error messages above have been
    produced. Frustrating. :-(

    Thanks, anyway.


walt <whrauser at> wrote:
> Fausto,
> This will keep the dos window open so you can see what is happening.
> (Windows 2000)
> """ Execute program in cmd window, /k keeps dos window open """
> import os
> myPy = 'c:/python22/lib/lib-tk/'
> os.execl('c:/winnt/system32/cmd.exe', '/k', myPy)
> # Could specify path to python if necessary
> #os.execl('c:/winnt/system32/cmd.exe', '/k', 'c:/python22/python.exe',
> myPy)
> But, I generally use the spawn series, since I want to return to my
> script after the program runs.
> Walt

More information about the Python-list mailing list