From: Hugh Sasse Date: 2005-11-03T22:05:02+09:00 Subject: Re: execeute gawk from inside ruby script On Thu, 3 Nov 2005, Robert Gilaard wrote: > Dear folks, > > how can I execeute a awk (or any other script) from > within ruby? > > Currently I'm looking into the exec and fork part of > the kernel class but I'm not too sure I'm on the right > trach. That is a right track, but not the only one. > > The while loop in the script looks like this in test: > > while i<=202 > location<< "#{i}" > exec "gawk -f fix_creacity.awk $location> defile.txt" > > i=i+1 > location="snapshot" > end > > But in the ruby book I have seen that after the ruby > script doesn't get after the exec. Exec overlays the process with the new one. fork() duplicates the process then when the child execs you have two different ones. The parent then wait for the child process to die. > > But I want to repeat this a few times so what could I > do? Every time the while statement gets executed, I > would like a new output file. To save on the apparent complexities of fork and exec, look at system(), and look at (0).upto(202) do |i| %x{gawk -f fix_creacity.awk #{location}#{i}> defile.txt} end For more fun look at open and what it says about "| ...", and for deeper exploration of this realm look at popen. > > Brdgs > Robert > > Hugh