FW: process output pipe autoflush

2000-12-11 Thread Mark Zvolanek

Many thanks to $Bill, Carl and Michael,

The cause was the buffering in the executable involved,
I had the coder insert fflush(stdout) after each printf statement.
Also my understanding on buffering has somewhat improved.
Thanks again.

|__
| Mark Zvolanek
| +612 9227 0479



-Original Message-
From: $Bill Luebkert [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, 5 December 2000 15:08
To: Mark Zvolanek
Cc: '[EMAIL PROTECTED]'
Subject: Re: process output pipe autoflush


Mark Zvolanek wrote:
 
 Hello,
 
 I have a problem with autoflush. Platform is Windows NT 4 / sp6.
 
 I use the following code:
 
 $command = 'executable.exe param1 ';#option 1
 # $command = 'DIR C:\ /S';  #option 2
 open (PIPE, "$command |");
 $| = 1;
 while (PIPE){
 print;
 }
 
 If I use line with (option 2) the output does not get buffered as
expected.
 If I use line with (option 1) the output of the executable is buffered.
 
 If I execute the line "executable.exe param1" on the DOS prompt
 the oputput is produced immediately.
 I tried both autoflush PIPE and select((select(PIPE), $| = 1)[0])
commands,
 I even print out the value of $| during execution, it is set to 1.
 
 What am I doing wrong?

How do you know the data is being buffered or not?

Are you doing this under CGI conditions?

Do you understand what buffering does?

It basically forces each line out individually (when $| is set) rather 
then waiting for an internal buffer (maybe 512/1024 bytes??) to fill before 
outputting.  Leaving STDOUT buffered ($| not set) is more efficient.

If you were to slip a sleep 1 into your loop, you would see the result 
since one would print one line every second and the other would wait several

seconds and then print several lines.

-- 
  ,-/-  __  _  _ $Bill Luebkert   ICQ=14439852
 (_/   /  )// //   DBE Collectibles   http://www.wgn.net/~dbe/
  / ) /--  o // //  Mailto:[EMAIL PROTECTED]   http://dbecoll.webjump.com/
-/-' /___/__/_/_http://www.freeyellow.com/members/dbecoll/
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users



RE: process output pipe autoflush

2000-12-06 Thread erskine, michael

Everybody, all of the issues being discussed here are fully explained in the
attatched link. I repeat myself...

 You should read M-J. Dominus's excellent Perl Journal 
 article, "Suffering
 from Buffering?". This will give you all the answers you need.
 
 http://perl.plover.com/FAQs/Buffering.html

Michael Erskine (MSEmtd)
mailto:[EMAIL PROTECTED]
JAPH
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users



RE: process output pipe autoflush

2000-12-05 Thread erskine, michael

 -Original Message-
 From: Mark Zvolanek [mailto:[EMAIL PROTECTED]]
 Sent: 05 December 2000 03:48
 To: '[EMAIL PROTECTED]'
 Cc: Mark Zvolanek
 Subject: process output pipe autoflush

 I have a problem with autoflush. Platform is Windows NT 4 / sp6.

Mark, (in fact everyone!)

You should read M-J. Dominus's excellent Perl Journal article, "Suffering
from Buffering?". This will give you all the answers you need.

http://perl.plover.com/FAQs/Buffering.html

In fact everyone who hasn't already should read *ALL* of M-J's articles - it
almost makes newsgroup support obsolete (except for all the Win32 caveats of
course!)...

http://perl.plover.com/


Michael Erskine (MSEmtd)
mailto:[EMAIL PROTECTED]
JAPH
 
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users



Re: process output pipe autoflush

2000-12-05 Thread $Bill Luebkert

"$Bill Luebkert" wrote:
 
 Mark Zvolanek wrote:
 
  Hi Carl,
  I am sorry I don't understand.
 
  I was talking about $| variable and not $!.
 
  I am trying to figure out why my perl code
  is buffering the (STDOUT) output of the executable
  even though I have set the variable $| to 1.
  Whereas when I execute the executable at
  the command prompt its output is not buffered.
 
  You also said:  The PIPE handle is an input handle.
  Why is it then my perl code below produces output
  as passed to it by the executable.
  ...
  while (PIPE){
  print;
  }
  ...
 
 A new little test shows some insight.  Maybe buffering isn't used when
 writing to the console (vs a file/pipe):
 
 Driver:
 

snip to last test block

 # this should print 1 line per second

Whoops, this last one should wait 10 seconds and then print all 10 lines
if buffering is on, but doesn't when going direct to console.

-- 
  ,-/-  __  _  _ $Bill Luebkert   ICQ=14439852
 (_/   /  )// //   DBE Collectibles   http://www.wgn.net/~dbe/
  / ) /--  o // //  Mailto:[EMAIL PROTECTED]   http://dbecoll.webjump.com/
-/-' /___/__/_/_http://www.freeyellow.com/members/dbecoll/
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users



Re: process output pipe autoflush

2000-12-05 Thread $Bill Luebkert

Mark Zvolanek wrote:
 
 Hi Carl,
 I am sorry I don't understand.
 
 I was talking about $| variable and not $!.
 
 I am trying to figure out why my perl code
 is buffering the (STDOUT) output of the executable
 even though I have set the variable $| to 1.
 Whereas when I execute the executable at
 the command prompt its output is not buffered.
 
 You also said:  The PIPE handle is an input handle.
 Why is it then my perl code below produces output
 as passed to it by the executable.
 ...
 while (PIPE){
 print;
 }
 ...

A new little test shows some insight.  Maybe buffering isn't used when 
writing to the console (vs a file/pipe):

Driver:

use strict;

$| = 1; # buffering off

# ARGV[0] = $|, ARGV[1] = sleep, ARGV[2] = count

# this should wait 10 seconds and then print all 10 lines

open PIPE, "c:\\perl\\bin\\perl pipe.pl 0 1 10 |" or 
  die "Error starting pipe: $!\n";
while (PIPE) {
print;
}
close PIPE;

# this should print 1 line per second

open PIPE, "c:\\perl\\bin\\perl pipe.pl 1 1 10 |" or 
  die "Error starting pipe: $!\n";
while (PIPE) {
print;
}
close PIPE;

$| = 0; # buffering on

# this should wait 10 seconds and then print all 10 lines

open PIPE, "c:\\perl\\bin\\perl pipe.pl 0 1 10 |" or 
  die "Error starting pipe: $!\n";
while (PIPE) {
print;
}
close PIPE;

# this should print 1 line per second

open PIPE, "c:\\perl\\bin\\perl pipe.pl 1 1 10 |" or 
  die "Error starting pipe: $!\n";
while (PIPE) {
print;
}
close PIPE;

__END__


Test exe (pipe.pl):

use strict;

print STDERR "buffer=$ARGV[0]; " if defined $ARGV[0];
print STDERR "sleep=$ARGV[1]; " if defined $ARGV[1];
print STDERR "count=$ARGV[2]\n" if defined $ARGV[2];

$| = $ARGV[0] if defined $ARGV[0];

my $count = 1000;
$count = $ARGV[2] if defined $ARGV[2];
for (my $ii = 0; $ii  $count; $ii++) {
print 
"$ii: Testing 1234567890 The quick brown fox jumped over the lazy dog's back\n";
sleep $ARGV[1] if defined $ARGV[1] and $ARGV[1]  0;
}
__END__


If you pipe the output to less, you get different results than if 
you let it go to console. 1-4 are the four exe executions.

1) wait 10; print 10
2) wait 1; print 1 - ten times
3) wait 10; print 10
4a) wait 10; print 10 (when going to pipe)
4b) wait 1; print 1 - ten times (when going to console)

-- 
  ,-/-  __  _  _ $Bill Luebkert   ICQ=14439852
 (_/   /  )// //   DBE Collectibles   http://www.wgn.net/~dbe/
  / ) /--  o // //  Mailto:[EMAIL PROTECTED]   http://dbecoll.webjump.com/
-/-' /___/__/_/_http://www.freeyellow.com/members/dbecoll/
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users



process output pipe autoflush

2000-12-04 Thread Mark Zvolanek

Hello,

I have a problem with autoflush. Platform is Windows NT 4 / sp6.

I use the following code:

$command = 'executable.exe param1 ';#option 1
# $command = 'DIR C:\ /S';  #option 2
open (PIPE, "$command |");
$| = 1;
while (PIPE){
print;
}

If I use line with (option 2) the output does not get buffered as expected.
If I use line with (option 1) the output of the executable is buffered.

If I execute the line "executable.exe param1" on the DOS prompt 
the oputput is produced immediately.
I tried both autoflush PIPE and select((select(PIPE), $| = 1)[0]) commands,
I even print out the value of $| during execution, it is set to 1.

What am I doing wrong?

Thanks,
|__
| Mark Zvolanek
| +612 9227 0479


___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users