subprocess equivalent for "os.execvp()"?
c.buhtz at posteo.jp
c.buhtz at posteo.jp
Mon Jan 9 03:36:21 EST 2023
Dear Eryk,
Am 08.01.2023 17:22 schrieb Eryk Sun:
> Avoid using any of the `os.exec*` functions on Windows. There's no
> support for replacing a Windows process image, so the `exec*()`
> functions simply spawn a child process and terminate the current one.
Thanks for bringing this up.
On Python for Windows what is the appropriate way how a process can call
itself again?
Let me give you an example [1]:
There is a project "bitcli" having two entry points
[project.scripts]
bitcli = "bitcli.__main__:main"
bitcli-root = "bitcli.__main__:run_main_as_root_via_policykit"
The first is usual.
But the second does call "bitcli" via "pkexec" to give it some root
rights.
This application is intended to be run as user or root by the user
himself.
def run_main_as_root_via_policykit():
cmd = ['pkexec', '--disable-internal-agent', 'bitcli']
# See https://github.com/python/cpython/issues/39569
os.execvp(cmd[0], cmd)
Is there a better way to achiev this?
[1] -- <https://codeberg.org/buhtz/bit_demo>
More information about the Python-list
mailing list