Buffering problems

J

Joe Van Dyk

I'm trying to redirect stdout and stderr of a program to a log file.

So, I'm doing something like:

$stdout.sync =3D true
$stderr.sync =3D true
$stdout.reopen File.open(some_log_file, "w")
$stderr.reopen File.open(some_log_file, "w")

exec 'program'

Standard out and error are being redirected to the log file, but they
are being buffered.

Any ideas on why that might be?

Thanks,
Joe
 
J

Joe Van Dyk

I'm trying to redirect stdout and stderr of a program to a log file.

So, I'm doing something like:

$stdout.sync =3D true
$stderr.sync =3D true
$stdout.reopen File.open(some_log_file, "w")
$stderr.reopen File.open(some_log_file, "w")

exec 'program'

Standard out and error are being redirected to the log file, but they
are being buffered.

Any ideas on why that might be?

Just found IO::fsync...
--------------------------------------------------------------- IO#fsync
ios.fsync =3D> 0 or nil
------------------------------------------------------------------------
Immediately writes all buffered data in _ios_ to disk. Returns
+nil+ if the underlying operating system does not support
_fsync(2)_. Note that +fsync+ differs from using +IO#sync=3D+. The
latter ensures that data is flushed from Ruby's buffers, but
doesn't not guarantee that the underlying operating system actually
writes it to disk.



I'm running on Linux. Is there any way to force the OS to write data
from Ruby's buffers to the disk all that time?
 
A

Ara.T.Howard

I'm trying to redirect stdout and stderr of a program to a log file.

So, I'm doing something like:

$stdout.sync = true
$stderr.sync = true
$stdout.reopen File.open(some_log_file, "w")
$stderr.reopen File.open(some_log_file, "w")

exec 'program'

Standard out and error are being redirected to the log file, but they
are being buffered.

Any ideas on why that might be?

did you mean

$stdout.reopen File.open(some_log_file, "w")
$stderr.reopen File.open(some_log_file, "w")
$stdout.sync = true
$stderr.sync = true

?

-a
--
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| Your life dwells amoung the causes of death
| Like a lamp standing in a strong breeze. --Nagarjuna
===============================================================================
 
J

Joe Van Dyk

did you mean

$stdout.reopen File.open(some_log_file, "w")
$stderr.reopen File.open(some_log_file, "w")
$stdout.sync =3D true
$stderr.sync =3D true

No. Why would the ordering make a difference?
 
N

nobuyoshi nakada

Hi,

At Fri, 14 Oct 2005 06:40:05 +0900,
Joe Van Dyk wrote in [ruby-talk:160499]:
$stdout.sync = true
$stderr.sync = true
$stdout.reopen File.open(some_log_file, "w")
$stderr.reopen File.open(some_log_file, "w")

exec 'program'

IO#sync flag is only for current process.
Standard out and error are being redirected to the log file, but they
are being buffered.

Any ideas on why that might be?

One way is to let the 'program' not to buffer its output.
Another way is to use pty.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top