On Jun 20, 2006, at 12:27 AM, Craig Beck wrote:

> I've got some code like this:
>
> sources = File.new 'file_list.txt'
> sources.each do |src|
> 	exec "mkdir #{some_dest}" unless File.exists some_dest
> 	exec "svn export #{src} #{some_dest}"
> end
> puts 'Done.'
>
> The problem is that ruby calls 'svn export' once for the first line  
> of sources and exits without looping through subsequent sources or  
> getttng to the line "puts 'Done.'"
>
> exec works just fine with the "mkdir" call.
>
> A couple of things:
> 1. I'm on Windows Server 2003

I'm not a windows guy so I don't know exactly how exec is interpreted  
on Windows, but on the Unix side:

exec causes the currently running program (i.e. Ruby) to be replaced  
with the new command.
Your "svn" command doesn't run because the first exec effectively  
replaced the Ruby interpreter with
"mkdir".  Sort of like invasion of the body-snatchers.  First the  
process is running Ruby and then it
is running "mkdir" and Ruby is gone.

The Unix idiom to handle what you want to do is to call fork first to  
create a child process and then
have the child process be replaced with the command via 'exec'.   
Rinse and repeat.

In your case, you might be better off using 'system' instead of  
'exec'.  System will take care of
forking and exec'ing the command for you.


Gary Wright