From: Gennady Bystritksy Date: 2005-06-28T03:23:28+09:00 Subject: Re: redirecting STDOUT Joe Van Dyk wrote: > Why doesn't this work? > > (#executable is a function that returns a string that contains a test > application that spits out some data) > > def start > pid = fork > if pid.nil? # In child > log = File.open(executable + ".log", "w") > STDOUT.reopen(log) > STDERR.reopen(log) > exec executable # Start program > exit > else # In parent > @pid = pid # Record new process id > Process.detach @pid # If the process dies, let it die > monitor # Start monitoring the process' status > end > end > > > Well, it works for the most part. The log file gets created, but > nothing gets written to it. Am I not redirecting output correctly? > > Thanks, > Joe > > Thanks, > Joe > Are you sure your "executable" is producing anything when launched the way you do it? You may try some STDERR.puts before "exec executable" to know for sure that something must be there. Also, I would do log.close before exec as the file descriptor is cloned anyway for stdout and stderr. Gennady.