Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Message-ID: <416D3499.6080708@x-ray.at> Date: Wed, 13 Oct 2004 15:58:49 +0200 From: Reini Urban User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; de-AT; rv:1.8a3) Gecko/20040817 MIME-Version: 1.0 To: Nuno Leitao CC: cygwin AT cygwin DOT com Subject: Re: Buffered output/Forked processes References: <8904DDEEB811D6118AF900508BB832FA080995E5 AT the-exch-c DOT ai DOT pri> In-Reply-To: <8904DDEEB811D6118AF900508BB832FA080995E5@the-exch-c.ai.pri> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Nuno Leitao schrieb: > Sorry, I should have stated my question better -- look at the following command on cygwin: > > % vmstat 1 > somefile.txt & > (...time passes...) > % ls -la somefile.txt > -rw-r--r-- 1 leitaon mkgroup- 0 Oct 13 13:48 somefile.txt > (...time passes...) > % ls -la somefile.txt > -rw-r--r-- 1 leitaon mkgroup- 4096 Oct 13 13:52 somefile.txt > > What is going on is that vmstat/cygwin/glibc/whatever is just buffering the output until the buffer is full (4096 bytes) at which point it flushes it. The effect I want is for each line outputed from vmstat to go straight into the file (or in my original example, into the pipe and the Perl script) -- the problem is *not* on the Perl script but the way vmstat is buffering the output. yes, our glibc (newlib) buffers. most libc implementations of printf do buffer. Use might want to use syswrite instead. So you have to fix vmstat to remove the output buffering to stdout. Can we see this script? Is vmstat perl? Are you sure the output from vmstat is not buffered? Or do say the cygwin pipe buffers implicitly? open( VMSTAT, "vmstat 5|" ); I've developed some tail -f like perl scripts like this to redirect live log data to a webbrowser and it worked ok on cygwin as on linux. But I did it like this: (you'll get the idea) check size, wait some sec, and print interim buffer if size changed. open(LOG, $log) or die "can't open $log: $!\n$usage"; seek(LOG, 0, SEEK_END); for (;;) { $_ = readline(*LOG); if ($grep) { # die at syntax errors. # highlight? eval { if (/$grep/i) { s|($grep)|$1|i; print $_, "
"; } }; die $@ if $@; } else { print $_, "
"; } for (my $size = -s LOG; $size == -s LOG; $i+=$sleep, sleep $sleep) { if ($i > $timeout) { print "\n
timeout
\n"; exit; } } LOG->clearerr(); } > -----Original Message----- > From: Reini Urban [mailto:rurban AT x-ray DOT at] > Sent: 13 October 2004 13:12 > To: Nuno Leitao > Cc: 'cygwin AT cygwin DOT com' > Subject: Re: Buffered output/Forked processes > > > Nuno Leitao schrieb: >> I have a Perl script which looks like: >> >> open( VMSTAT, "vmstat 5|" ); >> VMSTAT->autoflush( 1 ); >> while( ) { >> print $_; >> } >> >> Now, under Linux and other UNIX OS's this works fine, and "print $_" will >>print the vmstat output every 5 seconds since the output from vmstat is not >>buffered. Under Cygwin however, it seems vmstat will always buffer its >>stdout with the undesirable effect that lines come in batches as the output >>buffer gets full and is flushed by the Cygwin C libraries. >> >> Is there a way to go around this without having to patch and recompile >>vmstat or other binaries I might want to use in this way ? > > > basic perl question, not cygwin related. > $ perldoc -q buffer > $ perldoc -f select > > cygwin perl doesn't honor $| ? not true. > Because you told VMSTAT not to buffer. > But you shold have told it to STDOUT. > > open( VMSTAT, "vmstat 5|" ); > VMSTAT->autoflush( 1 ); > $| = 1; # STDOUT is selected so STDOUT will get unbuffered. > while( ) { > print $_; > } -- Reini Urban http://xarch.tu-graz.ac.at/home/rurban/ -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/