From: Eric Schwartz Date: 2002-11-16T02:43:28+09:00 Subject: Re: Problem writing to file after closing $stdout & $stderr ahoward writes: > perhaps something in the parent is writing to stderr/out? i ask because this > works fine for me Why shouldn't the parent write to stderr/out? The child should inherit its own copy of all open file descriptors (which at this point is just stdin, stdout and stderr). Did you mean the child may be writing? Here's a minimal example: 1 puts "before fork" 2 fork { 3 puts "in child" 4 logfile = File.open('/tmp/logfile','w') 5 logfile.sync=true 6 logfile.puts "before cleosing file descriptors" 7 $stdout.close 8 $stdout = nil 9 logfile.puts "closed $stdout" 10 $stderr.close 11 $stderr = nil 12 logfile.puts "closed $stderr" 13 $stdin.close 14 $stdin = nil 15 logfile.puts "closed $stdin" 16 } 17 puts "after fork, in parent" This crashes at the line "$stdout = nil" with: /tmp/test.rb:8: closed stream (IOError) from /tmp/test.rb:3:in 'fork' from /tmp/test.rb:3 This is what I don't get: I closed $stdout on the line before. Why does it appear to be writing to a closed stream on line 8? I get the same result if I try to replace line 8 with $stdout = $stderr -=Eric -- Come to think of it, there are already a million monkeys on a million typewriters, and Usenet is NOTHING like Shakespeare. -- Blair Houghton