in reply to how to get spool info from NT

In my limited understanding of this issue, I'd say you need to *read* the data from STDIN first to get the size of the data. Like this:

#!/usr/bin/perl -w use strict; # must use binmode on Windows to get actual byte length of file # otherwise line end processing will ruin our count binmode STDIN; local $/ = undef; my $input = <>; print length($input);

With this scriptlet saved as try.pl and using some html as input:

D:\tmp>perl -0777 -pe "42" try.html | perl try.pl 5409

I think your result from stat() is just applying to the contents of the console buffer you read from, but I am not sure about this, as I never had the idea of using stat() on STDIN, and have no idea currently what this really means.

Update: Zaxo and I performed some experimenting with this on our Linux boxes. For Zaxo (on a 2.4 kernel), stat()ing STDIN always gave 0 in field 7, for me (on a 2.2.16 kernel), it gave different values. We used this code to test:

perl -pe 'BEGIN{$|=1}' /usr/dict/words | perl -lne 'print ((stat STDIN +)[7])'|sort|uniq

So the message seems to be: you can't rely on stat()ing STDIN.

Christian Lemburg
Brainbench MVP for Perl
http://www.brainbench.com

Replies are listed 'Best First'.
Re: Re: how to get spool info from NT
by physi (Friar) on Jul 17, 2001 at 13:21 UTC
    Ok, but it's not possible to do so in my case, cause there may be a lot of data on STDIN. So I can't read all the data to a variable.
    I really need to know the size before the script is working with the data.

    Cheers

    ----------------------------------- --the good, the bad and the physi-- -----------------------------------

      Well OK, then read the stuff piecewise and save to a file. You *will* have to handle the data some time, I suppose, so you have to read it anyway.

      Christian Lemburg
      Brainbench MVP for Perl
      http://www.brainbench.com

        Actually I only send the data via a socket to a unix-server and don't work with the data :-)
        I need the length of the stream for generating a task-bar to show the user, how many percent is allready done.

        ----------------------------------- --the good, the bad and the physi-- -----------------------------------