Exec() not returning to ruby

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
  2. svn (Subversion) 1.3
  3. I’m not using the rscm gem with it’s subversion interface because
    I need to export and rscm doesn’t appear to do this (maybe I’ll see
    about adding it)

Any ideas why a call to svn wouldn’t return control to my ruby script?


Craig B.

http://www.luckybonza.com
AIM: kreiggers

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

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 W.

you should be use ‘system’ instead of ‘exec’.
look like this,
system ‘dir’
or
dir

both ok.

because ‘exec’ will replace the current process by running the given
external command.so

exec ‘dir’

never get here

u know?:slight_smile:
you can type ‘ri exec’ @ shell for more…

enjoy

Great!

system did the trick

between php, ruby, linux and mac osx at home, c# and windows at work
I have a hard time switching modes and remembering which is which.

On Jun 19, 2006, at 10:26 PM, [email protected] wrote:

puts ‘Done.’
I’m not a windows guy so I don’t know exactly how exec is
The Unix idiom to handle what you want to do is to call fork first


Craig B.

http://www.luckybonza.com
AIM: kreiggers