Gary Wright
6/23/2005 10:05:00 PM
On Jun 23, 2005, at 2:59 PM, Joel VanderWerf wrote:
> Panich, Alexander wrote:
>> Under Linux, by default, method Kernel.system(command) (backticks as
>> well) executes command in the subshell of SH type.
> Is this really true?
Hmm. I did some more poking. Without diving into the code too much
It looks like on most systems, Kernel.system emulates the behavior
of the Posix system() function instead of just calling it. Basically
if the command string has any characters that might need to be
interpreted by the shell (*;< and so on), then ruby fires up /bin/sh
to handle the command, otherwise Ruby just execs the program directly.
system "ls" # /bin/sh not started
system "ls *.rb" # /bin/sh started to handle filename expansion"
Note, that in both cases, Ruby is forking *first* and then starting
either the shell or the program.
If you use Kernel#exec then you have to managing forking in the
ruby code.
Gary Wright