[Python-Dev] Set program name through exec -a or environment variable
Hi, I would like to know if you're open to supporting `exec -a` or an environment variable for setting `argv[0]`, and have some pointers as to where that should be implemented. On Nixpkgs we typically use wrappers to set environment variables like PATH or PYTHONPATH for individual programs. Consider a program named `prog`. We move the original program `prog` to `.prog-wrapped` and then create a wrapper `prog` that does `exec -a prog .prog-wrapped`. Unfortunately `exec -a` does not work with Python. The process is still named `.prog-wrapped` (although that's not really a problem) but worse, `sys.argv[0]` is also `.prog-wrapped`. Currently we inject some code in programs that sets `sys.argv=[0] = "prog" but this is fragile and I would prefer to get rid of this. Kind regards, Frederik ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Set program name through exec -a or environment variable
exec -a would seem to end up setting argv[0] on the CPython interpreter itself, which I don't think is the desired effect... -- Ryan (ライアン) Yoko Shimomura > ryo (supercell/EGOIST) > Hiroyuki Sawano >> everyone else http://refi64.com On Mar 18, 2017 10:11 AM, "Freddy Rietdijk" wrote: > Hi, > > I would like to know if you're open to supporting `exec -a` or an > environment variable for setting `argv[0]`, and have some pointers as to > where that should be implemented. > > On Nixpkgs we typically use wrappers to set environment variables like > PATH or PYTHONPATH for individual programs. Consider a program named > `prog`. We move the original program `prog` to `.prog-wrapped` and then > create a wrapper `prog` that does `exec -a prog .prog-wrapped`. > > Unfortunately `exec -a` does not work with Python. The process is still > named `.prog-wrapped` (although that's not really a problem) but worse, > `sys.argv[0]` is also `.prog-wrapped`. Currently we inject some code in > programs that sets `sys.argv=[0] = "prog" but this is fragile and I would > prefer to get rid of this. > > Kind regards, > > Frederik > > > > ___ > Python-Dev mailing list > [email protected] > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: https://mail.python.org/mailman/options/python-dev/ > rymg19%40gmail.com > > ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Set program name through exec -a
Hi!
On Sat, Mar 18, 2017 at 02:15:12PM +0100, Freddy Rietdijk
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.
> Kind regards,
>
> Frederik
Oleg.
--
Oleg Broytmanhttp://phdru.name/[email protected]
Programmers don't die, they just GOSUB without RETURN.
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Set program name through exec -a or environment variable
On Sat, Mar 18, 2017 at 10:27:58AM -0500, Ryan Gonzalez wrote: > exec -a would seem to end up setting argv[0] on the CPython interpreter > itself, which I don't think is the desired effect... That's exactly what OP asked -- how to change that? > -- > Ryan () > Yoko Shimomura > ryo (supercell/EGOIST) > Hiroyuki Sawano >> everyone else > http://refi64.com > > On Mar 18, 2017 10:11 AM, "Freddy Rietdijk" wrote: > > I would like to know if you're open to supporting `exec -a` or an > > environment variable for setting `argv[0]`, and have some pointers as to > > where that should be implemented. > > > > On Nixpkgs we typically use wrappers to set environment variables like > > PATH or PYTHONPATH for individual programs. Consider a program named > > `prog`. We move the original program `prog` to `.prog-wrapped` and then > > create a wrapper `prog` that does `exec -a prog .prog-wrapped`. > > > > Unfortunately `exec -a` does not work with Python. The process is still > > named `.prog-wrapped` (although that's not really a problem) but worse, > > `sys.argv[0]` is also `.prog-wrapped`. Currently we inject some code in > > programs that sets `sys.argv=[0] = "prog" but this is fragile and I would > > prefer to get rid of this. > > > > Kind regards, > > > > Frederik Oleg. -- Oleg Broytmanhttp://phdru.name/[email protected] Programmers don't die, they just GOSUB without RETURN. ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Set program name through exec -a or environment variable
Oleg Broytman wrote: On Sat, Mar 18, 2017 at 10:27:58AM -0500, Ryan Gonzalez wrote: exec -a would seem to end up setting argv[0] on the CPython interpreter itself, which I don't think is the desired effect... That's exactly what OP asked -- how to change that? Maybe python itself should have an -a option, so that python -a blarg foo.py would run foo.py with sys.argv[0] == 'blarg'. -- Greg ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Set program name through exec -a or environment variable
https://pypi.python.org/pypi/setproctitle From: Python-Dev [mailto:[email protected]] On Behalf Of Freddy Rietdijk Sent: Saturday, March 18, 2017 9:15 AM To: Python-Dev Subject: [Python-Dev] Set program name through exec -a or environment variable Hi, I would like to know if you're open to supporting `exec -a` or an environment variable for setting `argv[0]`, and have some pointers as to where that should be implemented. On Nixpkgs we typically use wrappers to set environment variables like PATH or PYTHONPATH for individual programs. Consider a program named `prog`. We move the original program `prog` to `.prog-wrapped` and then create a wrapper `prog` that does `exec -a prog .prog-wrapped`. Unfortunately `exec -a` does not work with Python. The process is still named `.prog-wrapped` (although that's not really a problem) but worse, `sys.argv[0]` is also `.prog-wrapped`. Currently we inject some code in programs that sets `sys.argv=[0] = "prog" but this is fragile and I would prefer to get rid of this. Kind regards, Frederik ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Set program name through exec -a or environment variable
On 18.03.17 15:15, Freddy Rietdijk wrote: I would like to know if you're open to supporting `exec -a` or an environment variable for setting `argv[0]`, and have some pointers as to where that should be implemented. On Nixpkgs we typically use wrappers to set environment variables like PATH or PYTHONPATH for individual programs. Consider a program named `prog`. We move the original program `prog` to `.prog-wrapped` and then create a wrapper `prog` that does `exec -a prog .prog-wrapped`. Unfortunately `exec -a` does not work with Python. The process is still named `.prog-wrapped` (although that's not really a problem) but worse, `sys.argv[0]` is also `.prog-wrapped`. Currently we inject some code in programs that sets `sys.argv=[0] = "prog" but this is fragile and I would prefer to get rid of this. You can move the original program `prog` into the subdirectory `.wrapped` and then create a wrapper `prog` that does `exec .wrapped/prog` or `exec python3 .wrapped/prog`. ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
