[issue42648] subprocess: add a helper/parameter to catch exec() OSError exception

2021-09-21 Thread STINNER Victor
STINNER Victor added the comment: I failed finding time to finish to design this feature. I'm not convinced that it's really needed. I abandoned my idea of deprecating os.popen(): bpo-42641. I close the issue. -- resolution: -> rejected stage: patch review -> resolved status: open

[issue42648] subprocess: add a helper/parameter to catch exec() OSError exception

2020-12-15 Thread Eryk Sun
Eryk Sun added the comment: I suggesting changing the name to indicate that only OSError exceptions are suppressed, not SubprocessError exceptions. Maybe call it no_oserror. As to the status code to use, if you want a a common code that can't interfere, it has to be either a negative value

[issue42648] subprocess: add a helper/parameter to catch exec() OSError exception

2020-12-15 Thread Gregory P. Smith
Gregory P. Smith added the comment: arguably run() with check=True could've turned the OSError into a CalledProcessError [can't do that now, someone surely depends on it]. So if both are supplied, perhaps it does that instead of returning a CompletedProcess with .oserror set? the API

[issue42648] subprocess: add a helper/parameter to catch exec() OSError exception

2020-12-15 Thread Gregory P. Smith
Gregory P. Smith added the comment: We could also be thinking too low level here. We don't have to re-use returncode for this or do it on POpen itself. This could be done at the `run()` API level and CompletedProcess could be given state indicating success or failure of the exec itself.

[issue42648] subprocess: add a helper/parameter to catch exec() OSError exception

2020-12-15 Thread STINNER Victor
STINNER Victor added the comment: I updated my PR 23790 to add many usage of the new parameter, to see which kind of code would benefit of it. -- Use case: Get the output of a command, don't fail if the command doesn't exist. Example: get "gcc --version" output. It's common to redirect

[issue42648] subprocess: add a helper/parameter to catch exec() OSError exception

2020-12-15 Thread STINNER Victor
STINNER Victor added the comment: https://docs.python.org/dev/library/subprocess.html#subprocess-replacements documentation suggests to replace os.popen(cmd, "w") with Popen(cmd, stdin=PIPE): without shell=True. My problem is that the replacement does change the behavior if the command does

[issue42648] subprocess: add a helper/parameter to catch exec() OSError exception

2020-12-15 Thread Gregory P. Smith
Gregory P. Smith added the comment: I suggest just adding a couple options to getstatusoutput instead of wrangling new to-catch-or-not-to-catch APIs if code like your test_posix example is what you want to replace. -- ___ Python tracker

[issue42648] subprocess: add a helper/parameter to catch exec() OSError exception

2020-12-15 Thread Gregory P. Smith
Gregory P. Smith added the comment: The shell was isolating the user from the exec error by always existing and turning the exec error into a status return. >>> subprocess.run('foo', shell=True) /bin/sh: line 1: foo: command not found CompletedProcess(args='foo', returncode=127) >>>

[issue42648] subprocess: add a helper/parameter to catch exec() OSError exception

2020-12-15 Thread STINNER Victor
STINNER Victor added the comment: I wrote PR 23790 which adds exec_raise=True parameter to subprocess.Popen. exec_raise=False avoids try/except OSError. I dislike the "exec_raise" parameter name. The function is not related to exec, but more specific to OSError. A better name may include

[issue42648] subprocess: add a helper/parameter to catch exec() OSError exception

2020-12-15 Thread STINNER Victor
Change by STINNER Victor : -- keywords: +patch pull_requests: +22647 stage: -> patch review pull_request: https://github.com/python/cpython/pull/23790 ___ Python tracker ___

[issue42648] subprocess: add a helper/parameter to catch exec() OSError exception

2020-12-15 Thread STINNER Victor
New submission from STINNER Victor : While working on on bpo-42641 "Deprecate os.popen() function", I tried to replace os.popen() with a subprocess function, to avoid relying on an external shell. Example from test_posix: with os.popen('id -G 2>/dev/null') as idg: groups