From: Eric Schwartz Date: 2002-11-15T09:41:37+09:00 Subject: Problem writing to file after closing $stdout & $stderr So I have a program now that starts off tests on remote machines, and is supposed to fork itself off, wait for the tests to finish, and fetch their logfiles back to the server. Here's the bit of relevant code: .... def closeFileHandles if($opt_debug) $stdin.close() $stderr.reopen('/tmp/stderr', 'a') $stdout = $stderr else $stdout.close(); $stderr.close(); $stdin.close() end end def RunTest(test,run_id) handle = startTest(@machine, test, run_id) fork { logfile = File.open('/tmp/testout', 'a') logfile.sync = true logfile.puts "about to close filehandles" closeFileHandles() logfile.puts "waiting for test to finish" sleep 20 while ProcessRunning?(handle, run_id) logfile.puts "go get logfiles" getLogFiles(test, run_id) logfile.close() } end The problem is, if $opt_debug is not set, and $stdout, $stderr, and $stdin are closed, then no data past "about to close filehandles" gets written to /tmp/testout. Actually, something seems to crash the child during or after closeFileHandles(), since I wrote this code to debug why the logfiles weren't getting copied back. If I'm missing something, then please clue me in; I've been tearing my hair out trying to fix this. -=Eric -- Come to think of it, there are already a million monkeys on a million typewriters, and Usenet is NOTHING like Shakespeare. -- Blair Houghton