When you use %x{}, ruby use a pipe you can see it
…
Guy Decoux
Hi,
thanks for your time, but i do not understand the answer. Let me
rephrase the question:
From what i have seen in the docs, Kernel.exec executes an OS command
in the current process, and Kernel.system creates a new subprocess to
execute the command. The question is, %x{} is an alias for exec or
system? ie does it create a new process?
if any program (under *nix – win32 is totally different this way) calls
the exec() function (in C), the process calling it is replaced by the
new program. The usual way a C program spawns a sub-process is with a
fork() call, to make a copy of the parent process, then one of them will
call exec(), getting itself replaced with the subprocess. Not entirely
intuitive, but it works. If Ruby were to use exec, the script would stop
at the first use of %x{}. %x{} is an alias for system.
···
On Sat, 2003-07-05 at 03:04, George Moschovitis wrote:
When you use %x{}, ruby use a pipe you can see it
…
Guy Decoux
Hi,
thanks for your time, but i do not understand the answer. Let me
rephrase the question:
From what i have seen in the docs, Kernel.exec executes an OS command
in the current process, and Kernel.system creates a new subprocess to
execute the command. The question is, %x{} is an alias for exec or
system? ie does it create a new process?
if any program (under *nix – win32 is totally different this way) calls
the exec() function (in C), the process calling it is replaced by the
new program. The usual way a C program spawns a sub-process is with a
fork() call, to make a copy of the parent process, then one of them will
call exec(), getting itself replaced with the subprocess. Not entirely
intuitive, but it works. If Ruby were to use exec, the script would stop
at the first use of %x{}. %x{} is an alias for system.
slightly related…
could’nt we emulate Kernel.fork on windows using some CreateProcess
magic?
At least, would’nt be useful a Kernel.spawn that appears as fork+exec
on nix and CreateProcess on win ?