From: Craig Beck Date: 2006-06-22T12:13:11+09:00 Subject: Re: exec() not returning to ruby 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, gwtmp01@mac.com wrote: > > 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 > > > -- Craig Beck http://www.luckybonza.com AIM: kreiggers