[Python] os.execve() runs in the wrong directory

Discussão em 'Python' iniciado por Stack, Setembro 17, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying spawn a new process with the function execve() from the os module. I need to spawn a new process and do some stuff in another directory, but it won't change.

    import os

    os.execve('/bin/ls', ['/bin/ls'], {'PATH': '/tmp'})


    When I ran this code, I got the content of the directory where I am, not from the /tmp directory. What am I doing wrong? I cannot use os.chdir() or change the way how the run command (like use the subprocess module).

    Continue reading...

Compartilhe esta Página