[Ruby] Launching script/runner from within Rails
Mike Mondragon
mikemondragon at gmail.com
Sun Feb 11 12:18:32 PST 2007
On 2/9/07, Eric Hodel <drbrain at segment7.net> wrote:
> On Feb 9, 2007, at 13:58, Mike Mondragon wrote:
> > I couldn't get rmagick to install onto a FreeBSD box so I just use the
> > real Image Magic composite program to process an image. Page 141 of
> > the PickAxe book shows an exec/wait example for long running processes
> > and that's what I use. The output still goes to standard out. How
> > would I control output of the long running process in such a way as
> > the back tick style? Or is there a way to wait on a subprocess spun
> > from the back tick?
> >
> > wm="/usr/bin/composite -gravity southeast -watermark 25 #{wmimg}
> > #{inimg} #{outimg}"
> > exec(wm) if fork.nil?
> `#{wm}`
> Process.wait
>
> See also the ri for Process.wait, popen and open3
Thanks for the tip, this is how I'm doing it now for anyone
interested. I read on another list that if the process being executed
with popen has output to stderr one needs to include a shell level
stderr redirect. So for sh/bash 2>&1 redirects stderr to stdout and
the below snippet will capture all the of the output of the
subprocess, wait for the subprocess to complete, and even capture the
exit status of the subprocess.
out = IO.popen("/bin/somecommand 2>&1")
Process.wait
e = $?.exitstatus
More information about the Ruby
mailing list