From: Mario Camou Date: 2009-09-21T10:44:38+09:00 Subject: Re: Writing to STDOUT after closing controlling terminal --001636ed741bbaf34d04740c9fbf Content-Type: text/plain; charset=ISO-8859-1 As far as killing the controlling terminal is concerned, AFAIK it's standard Unix practice. If you want the process to stay alive even if you kill the terminal, you either redirect its stdin/stdout or use nohup. -Mario. -- I want to change the world but they won't give me the source code. On Mon, Sep 21, 2009 at 03:14, Matt Bleh wrote: > Hi, > I don't know if this is a dumb question or not (I hope it isn't), but it > seems to me there's something wrong here. I've been using Ruby for a > long time now, and I never noticed this (maybe it wasn't working like > this in the past), and it just seems odd. > If I write the following code: > > sleep(5) > begin > puts 'hi!' > rescue > File.open('output', 'w') {|io| io.puts $!.message } > end > > And execute it in Ruby 1.9.1p243 in a graphical terminal (e.g.: konsole) > as a foreground process I obviously get this: > > $ ./test.rb > hi! > > And there's no "output" file created sine no exception was raised. > > Now, If I do: > $ ./test.rb & > [1] 28137 > and immediately close konsole, 5 seconds later I get: > $ cat output > Input/output error - > > Is this ok? I seems to me that one shouldn't have to care if the > controlling terminal is closed when doing "puts" to avoid this exception > from ending my ruby process. > > As a sidenote, with Ruby 1.8.7p174 the process doesn't get any > exception. If now I write (to check for normal process completion): > > sleep(5) > begin > puts 'hi!' > File.open('output2', 'w') {|io| io.puts 'ok' } > rescue > File.open('output', 'w') {|io| io.puts $!.message } > end > with > > and execute it as before, I get the "output2" file with the "ok" string > in it. > > Is this a bug? a feature? > > Thank you, > Matt > -- > Posted via http://www.ruby-forum.com/. > > --001636ed741bbaf34d04740c9fbf--