From: Andrew Timberlake Date: 2009-01-05T16:21:23+09:00 Subject: Re: Question about run external program in Ruby ------=_Part_246798_7815664.1231140147856 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Mon, Jan 5, 2009 at 8:08 AM, Zhao Yi wrote: > I use this method to run a external program in ruby: > > io=IO.popen("lsa 2>&1")do |f| > while line =f.gets do > puts line > end > end > > I can get both stdout and stderr output but how can I get the command > return value? > > thanks. > -- > Posted via http://www.ruby-forum.com/. > > Try the following: io=IO.popen("ruby some_file_that_doesnt_exist")do |f| while line =f.gets do puts line end end puts $?.exitstatus #returns - 1 -- Andrew Timberlake http://ramblingsonrails.com http://www.linkedin.com/in/andrewtimberlake "I have never let my schooling interfere with my education" - Mark Twain ------=_Part_246798_7815664.1231140147856--