Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

how to get spool info from NT

by physi (Friar)
on Jul 17, 2001 at 10:20 UTC ( [id://97258]=perlquestion: print w/replies, xml ) Need Help??

physi has asked for the wisdom of the Perl Monks concerning the following question:

And once again a Win question :)
I have a perl script invoked by RedMon -Redirection Port Monitor.
I read from STDIN and want to know which size the data from STDIN is. I've tried the following:
@status = stat(STDIN); $size=$stat[7]
Ok when I look into my WinNT printer-status window, I get the Information: Size: 4,00KB/80,7 KB. This shows me, that 4 K are allready sent to my script from totalling 80,7 KB data.

My perl stat(STDIN) gives me only the 4K, not the 80,7 K which I wanted to get, cause the rest of the data is somewhere in the spooler.
Is there a possibility to get access to this printer-spool Information from NT? Or must I save STDIN to a file first, than get the size info and after that process the script with the temporary created file?

Thanks for any help.

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

Replies are listed 'Best First'.
Re: how to get spool info from NT
by clemburg (Curate) on Jul 17, 2001 at 12:25 UTC

    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

      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

Re: how to get spool info from NT
by MZSanford (Curate) on Jul 17, 2001 at 13:01 UTC
    NT is not my strong point, but i believe to get access to the spooler status your will need to use either Win32::API and the correct DLL, or write an xs module.

    The problem with this approach is that you have to find the print jobs in question. there is some code here thats shows how to get printer status, which should give an idea of the functions for using Win32::API or XS.

    I am thinking there must be another way, and will post again if i find it.
    OH, a sarcasm detector, that’s really useful
Re: how to get spool info from NT
by joefission (Monk) on Jul 17, 2001 at 18:38 UTC
    Update: Thanks to crazyinsomniac for pointing out the proper URL for the working and featured script.

    Paul Papour wrote a perl based print monitor, NTPStat.pl.

    If you use activestate's perl, all modules required, except Win32::Service, are already installed.

    Basic rundown:
    Connect to the print server registry to find where the spooler lives.
    Connect to the spooler directory.
    Each subdirectory is the printer name.
    Print information files are extracted and displayed.
    It also provides the ability to delete print jobs and control the Spooler Service.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://97258]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-03-28 08:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found