[Python-Dev] Set program name through exec -a

Nick Coghlan ncoghlan at gmail.com
Sun Mar 19 07:30:53 EDT 2017


On 19 March 2017 at 01:42, Oleg Broytman <phd at phdru.name> wrote:

> Hi!
>
> On Sat, Mar 18, 2017 at 02:15:12PM +0100, Freddy Rietdijk <
> freddyrietdijk at fridh.nl> wrote:
> > I would like to know if you're open to supporting `exec -a` or an
>
>    Not everyone here knows what `exec -a` is so let me say that it's a
> bashism that sets program's name. `exec prog` is interpreted as a system
> call `exec('prog', 'prog')` and  `exec -a name prog` is interpreted as
> `exec('prog', 'name')`.
>
>    Currently sys.argv[0] is the name of the script and it should stay
> that way. But it would be interesting to preserve argv[0] from C and
> expose it via sys in addition to sys.executable. Something like
> sys.original_prog_name. Then the OP can do anything application-specific
> -- set sys.argv[0], call setproctitle, whatever.
>

There are a lot of other ways that the C level argv contents can differ
from what's published in "sys.argv" (especially when things are run with
-m, -c, or by executing a zipfile or directory rather than a Python script
directly).

https://bugs.python.org/issue14208 proposes offering an attribute like
"sys._raw_argv" to get the full details of how Python was invoked.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20170319/116fca30/attachment.html>


More information about the Python-Dev mailing list