Can't seem to understand fork & exec

Hello

I think that fork & exec is something really useful, but I just can't seem to understand it.
Could someone make a simple example of fork & exec?

If I wanted to open a Python file for example (python.py), how would that go with fork & exec?

Also, does it works on Linux and Windows?

Thanks for reading,
Niely
No one who can explain me fork & exec in Linux and Windows to open a python script?
closed account (EwCjE3v7)
I don't think your gonna get an answer here, you will need to try another forum.
Neither 'fork' nor 'exec' are valid commands in the cmd.exe shell, COM\WMIC or the WinAPI. "exec" is the name of a method in vb script for the 'WshShell' object, however that doesn't have much to do with what you are asking about here.

To execute an external process in Windows you would normally use either the "ShellExecute()" function found here: http://msdn.microsoft.com/en-us/library/windows/desktop/bb762153(v=vs.85).aspx or the "CreateProcess()" function found here: http://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx . In COM there are a few more steps involved but it isn't difficult if you're interested.

To launch a script like you are describing you would usually have to launch the interpreter and pass the name and directory of the script in as one of the arguments.
I got the code to do it.
int pid = fork();
if (pid == 0) {
execl("/usr/bin/python", "python", "python.py", NULL);
}


The only problem is, that the first Python user-input shows up, but when I enter something in the Python user-input, press enter, but then my program jumps back to the C++ and continue the code after the execl...

How do I make my C++ program keep running the Python until it ends?
Topic archived. No new replies allowed.