• Re: subprocess equivalent for =?UTF-8?Q?=22os=2Eexecvp=28=29=22?= =?UTF

    From c.buhtz@posteo.jp@21:1/5 to All on Mon Jan 9 08:36:21 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>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)