Python Forum
what is the Pythonic way to do os.execve()
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
what is the Pythonic way to do os.execve()
#1
what is the Pythonic way to do os.execve() with keyword arguments like stdout= and stderr= ? basically, i want a command to replace the existing process instead of starting a new one. the various .Popen() methods create a new process. i want the command to run in the existing process with STDOUT and/or STDERR redirection.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
From the linux manual execve(2)
Quote: • By default, file descriptors remain open across an execve().
File descriptors that are marked close-on-exec are closed; see
the description of FD_CLOEXEC in fcntl(2). (If a file
descriptor is closed, this will cause the release of all
record locks obtained on the underlying file by this process.
See fcntl(2) for details.) POSIX.1 says that if file
descriptors 0, 1, and 2 would otherwise be closed after a
successful execve(), and the process would gain privilege
because the set-user-ID or set-group-ID mode bit was set on
the executed file, then the system may open an unspecified
file for each of these file descriptors. As a general
principle, no portable program, whether privileged or not, can
assume that these three file descriptors will remain closed
across an execve().
« We can solve any problem by introducing an extra level of indirection »
Reply
#3
i've done execve() many times in my C programming. what i need to do in this little project is to invoke a command in the same process as the script invoking it. in Bash, this done by having "exec " in front of the command. i also need to direct its output to specific files. there is no such option in os.execve() to do such a redirection. i thought maybe some other method in some other module might have a "invoke in caller process" option in addition to ways to redirect. for now, i am doing the redirection using os.open() and os.dup2(). but this depends on file descriptors.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020