Home > Enterprise >  Running a Linux Executable from C/C Executable Without Use of system() or system() Wrappers
Running a Linux Executable from C/C Executable Without Use of system() or system() Wrappers

Time:03-02

I am looking for a way to execute a Linux executable from a separate Linux Executable that was compiled from C or C . However, I have looked at numerous Stack Overflow posts which all direct the user asking to use the system() function or a wrapper of the system function and I do not want a program that relies on the shell, because it could easily fall apart if it was transferred to a different operating system with a different shell.

In the post How do I execute an external program within C in Linux with arguments, the second answer states that execve() is a wrapper for the system() function, and this makes me wary of the other functions in the exec() family.

I have also looked at the following articles:

All help is appreciated!

CodePudding user response:

execve() is not a wrapper for system(); it is a wrapper for the execve syscall itself.

execve() replaces the current process, so you’ll probably need to fork() and then execute execve() in the child process, thereby emulating the behaviour of system().

  • Related