"python.exe has stopped working" when os.execl() runs on Windows 7

D

Dave Angel

Was trying os.execl() and got a "python.exe has stopped working" on my Windows 7 Ultimate SP1 x64 desktop.

I'm using Python 2.7.4 and that happens when the second arg is ''. For example:

os.execl('filename.exe','')


Wtf? :(

http://postimg.org/image/vdliyuenh/

Do you really have a program called filename.exe ?

Are you by any chance running this inside some shell or debugger, like
IDLE or KOMODO? Or is it a GUI program ? More specifically, does it
still give an error like that if you have a two-line Python program:
import os
os.execl('filename.exe', '')

execl is supposed to replace the current (python) program, with the
filename.exe one. But if the current program has any OS resources in
use (like file objects), they don't get flushed/released.

The execl was intended for use on Unix, and Windows can't really do what
it's documented to do.

If you don't get any useful answers here, I'd suggest going to
multiprocess module.
 
C

cormogram

Yes, just those two lines cause the error. 'filename.exe' exists and runs ok in the command prompt. Any other executable cause the problem, also '', for example:

os.execl('','')

If doesn't work on Windows it should give an error message, right?
 
D

Dave Angel

Yes, just those two lines cause the error. 'filename.exe' exists and runs ok in the command prompt. Any other executable cause the problem, also '', for example:

os.execl('','')

If doesn't work on Windows it should give an error message, right?

I'm not running Windows any more, so it's hard to be conclusive. When I
saw the description, I just assumed it'd be problematic under Windows.
That's why I had never played with it. By the time I escaped to Linux,
I was used to subprocess, so I still never played with execl. But why
you should get that error on a console program run from the cmd prompt,
I have no idea.
 
C

cormogram

Probably a bug I suppose. :(

I've used subprocess before and it works fine. I was just learning about the os module. os.execl() works if you provide no nulls, for example:

os.execl('c:\\bin\\filename.exe','filename.exe','arg1')

Is there the place to open a ticket for Python developers? Who keeps the os module?
 
N

Nobody

Was trying os.execl() and got a "python.exe has stopped working" on my
Windows 7 Ultimate SP1 x64 desktop.

I'm using Python 2.7.4 and that happens when the second arg is ''. For
example:

os.execl('filename.exe','')

Note that, by convention, the second argument should normally also be the
filename (the second argument will be available to the program as
argv[0]), e.g.:

os.execl('filename.exe','filename.exe')

If successful, the exec* functions don't return. On Unix, the new program
replaces the existing program in the current process. IIRC, the Windows
version executes the program in a child process then exit()s upon
completion.

The exec* functions probably shouldn't be used within a program which uses
any of the more complex OS features (e.g. GUI), as they will block event
processing, background threads, etc.
 
C

cormogram

I did that but unfortunately the 'bug' persists. :(

I've chosen the os module because I though it would be more portable. :/

Was trying os.execl() and got a "python.exe has stopped working" on my
Windows 7 Ultimate SP1 x64 desktop.

I'm using Python 2.7.4 and that happens when the second arg is ''. For


os.execl('filename.exe','')



Note that, by convention, the second argument should normally also be the

filename (the second argument will be available to the program as

argv[0]), e.g.:



os.execl('filename.exe','filename.exe')



If successful, the exec* functions don't return. On Unix, the new program

replaces the existing program in the current process. IIRC, the Windows

version executes the program in a child process then exit()s upon

completion.



The exec* functions probably shouldn't be used within a program which uses

any of the more complex OS features (e.g. GUI), as they will block event

processing, background threads, etc.
 
F

Fábio Santos

Cannot reproduce on windows 7 ultimate

Steps taken:

Start cmd
cd to Desktop where I have a GUI application
run python on the console
import os
os.execl('exe.exe', 'exe.exe')

<python stops at this point and starts GUI application as expected>
 
C

cormogram

It works fine as long as you don't provide a null string ('') to os.execl(), such as:

os.execl('filename.exe','')
 
C

cormogram

It isn't, but it doesn't matter because all executables I've tried cause the error, even "ping.exe". Just try:

os.execl('ping.exe', '')

And it will cause the "python.exe has stopped working" error message.
 
F

Fábio Santos

Reproduced in Windows 7 Ultimate:

At this point the REPL freezes, and windows prompts me to close Python
since it stopped responding.
 
N

Neil Cerutti

Reproduced in Windows 7 Ultimate:


At this point the REPL freezes, and windows prompts me to close Python
since it stopped responding.

To repeat others and the documentation:

In either case, the arguments to the child process should start
with the name of the command being run, but this is not
enforced.

The argument list must contain the executable as its first
argument. Python indeed crashes if I don't include the first
argument as directed.

In any case, on Windows I would normally need to do something
like this instead:

os.execlp('cmd.exe', 'cmd.exe', '/K', 'ping.exe')
 

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

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top