python / cpython

The Python programming language
https://www.python.org
Other
63.51k stars 30.42k forks source link

Cannot `os.spawnl` with no arguments #126931

Open CitrusWire opened 5 hours ago

CitrusWire commented 5 hours ago

Bug report

Bug description:

Python 3.8 and 3.11.9

Probably related to: https://github.com/python/cpython/issues/52284 Seems to be the same as: https://github.com/python/cpython/issues/63130

A number of bugs:

1) - Doesn't work with no arguements.

>>> os.spawnl(os.P_NOWAIT, "c:\path_to_some_program\app.exe")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<frozen os>", line 930, in spawnl
ValueError: spawnv() arg 2 cannot be empty

2) If I try and make the arguement empty it also fails. This means that I am forced to send an arguement that may trigger an unknown behaviour in the spawned application.:

>>> os.spawnl(os.P_NOWAIT, "c:\path_to_some_program\app.exe", '')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<frozen os>", line 930, in spawnl
ValueError: spawnv() arg 2 first element cannot be empty

2) If any aspect of this is intended, then the documentation needs to be updated to explicitly say this. Currently it implies any arguments are optional. (Honestly, the docs for this are bad generally.)

CPython versions tested on:

3.11

Operating systems tested on:

Windows

ronaldoussoren commented 4 hours ago

Note that the arguments passed are all arguments seen by the program, including argv[0].

The example in the docs at https://docs.python.org/3/library/os.html#os.spawnvpe shows this:


import os
os.spawnlp(os.P_WAIT, 'cp', 'cp', 'index.html', '/dev/null')

Note that 'cp' is listed twice, first as the name of the executable to start and then as the value seen in argv[0] of the spawned program.

picnixz commented 58 minutes ago

I think it's a doc issue but I can't be entirely sure about it. spanwl has a signature (mode, path, ...) so it's correct to perhaps assume that 2 arguments is enough.