This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.execl doesn't allow for empty string in mac
Type: Stage: resolved
Components: macOS Versions: Python 3.7, Python 3.6, Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: ned.deily, ronaldoussoren, siming85
Priority: normal Keywords:

Created on 2019-05-27 16:08 by siming85, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg343655 - (view) Author: Siming Yuan (siming85) * Date: 2019-05-27 16:08
the following works in Linux

import os
os.execl('/bin/bash', '')

doesn't in mac:
>>> import os
>>> os.execl('/bin/bash', '')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/me/.pyenv/versions/3.6.4/lib/python3.6/os.py", line 527, in execl
    execv(file, args)
ValueError: execv() arg 2 first element cannot be empty

works if you add a space
>>> os.execl('/bin/bash', ' ')

notice the space in 2nd argument.

technically it is also possible to run a command without arguments - why not allow for the case where *args is []?

>>> os.execl('/bin/bash')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/siyuan/.pyenv/versions/3.6.4/lib/python3.6/os.py", line 527, in execl
    execv(file, args)
ValueError: execv() arg 2 must not be empty
>>>
msg343662 - (view) Author: Siming Yuan (siming85) * Date: 2019-05-27 17:17
actually just learned that argv0 is program name.

in that case is that because of a platform difference where in macOS it doesn't allow for program name to be '' and in linux it does?
msg343736 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2019-05-28 06:51
Which exact python version did you test?  The current codebase raises this exception on all platforms, not just macOS (see os_execv_impl in Modules/posixmodule.c)

The behaviour of raising an exception was introduced in issue 28732 for Windows, not sure when that code was refactored to raise the exception on all platforms.
msg343857 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2019-05-29 03:11
The behavior was changed in Python 3.6 for all platforms to catch this error; see Issue28732.
History
Date User Action Args
2022-04-11 14:59:15adminsetgithub: 81248
2019-05-29 03:11:39ned.deilysetstatus: open -> closed
resolution: not a bug
messages: + msg343857

stage: resolved
2019-05-28 06:51:10ronaldoussorensetmessages: + msg343736
2019-05-27 17:17:43siming85setmessages: + msg343662
2019-05-27 16:08:47siming85create