From: "Ara.T.Howard" Date: 2005-07-05T07:03:40+09:00 Subject: Re: Exececuting another application from within ruby On Tue, 5 Jul 2005, Nigel Wilkinson wrote: > Hi folks > > I have a smell application from which I wish to display a file using an > external helper programme. > > Lets say > app = the external programme > file = the file to be displayed > > I've tried > > system(app, file) > > This works but it blocks my application. How can I fire up the helper > application in the background? def background command Thread::new(command, Thread::current) do |cmd, cur| begin pipe = IO::popen cmd true while pipe.gets and pipe.close $?.exitstatus rescue Exception => e cur.raise e end end end thread = background 'long-running' ... ... ... p thread.value # exitstatus hth. if you need control over stdout and stderr check out session. it provides thread safe execution. require 'session' def background command sh = Session::new Thread::new(command, Thread::current) do |cmd, cur| begin stdout, stderr = sh.execute cmd [stdout, stderr, sh.status] rescue Exception => e cur.raise e end end end thread = background 'long-running' ... ... ... p thread.value # [stdout, stderr, exitstatus] session also allows thread safe stuff like def background command, widget sh = Session::new Thread::new(command, Thread::current) do |cmd, cur| begin sh.execute(cmd) do |stdout, stderr| widget.update stdout, stderr end sh.status rescue Exception => e cur.raise e end end end hth. -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | My religion is very simple. My religion is kindness. | --Tenzin Gyatso ===============================================================================