- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Perl Network Printing Script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-20-2007 05:43 AM
тАО06-20-2007 05:43 AM
Searching Google I found info indicating that I have to open a socket to the destination IP address and port and dump the data which will
transparently be sent to the printer. What module do I used to open the socket?
use strict;
my $port='xxxx';
my $default_printer='xx.xx.xx.xx';
open(OUTPUT_PRINTER,"> \\\\$default_printer\\$port") || die "Unable to
open printer: $!\n"; print OUTPUT_PRINTER "This is a test Line\n";
Appreciate all help.
JC
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-20-2007 05:50 AM
тАО06-20-2007 05:50 AM
Re: Perl Network Printing Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-20-2007 05:51 AM
тАО06-20-2007 05:51 AM
Re: Perl Network Printing Script
http://search.cpan.org/~dmlloyd/Net-LPR-1.007/LPR.pod
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-20-2007 06:01 AM
тАО06-20-2007 06:01 AM
Re: Perl Network Printing Script
http://search.cpan.org/~cfuhrman/Net-Printer-1.04/lib/Net/Printer.pm
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-20-2007 06:42 PM
тАО06-20-2007 06:42 PM
Re: Perl Network Printing Script
Network printers use a variety of port numbers.
Common ones are 9100 for JetDirects, and 515 for LPD based printers.
What printer are you using specifically ?
Hope this helps,
Regards,
Rob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-20-2007 07:04 PM
тАО06-20-2007 07:04 PM
Re: Perl Network Printing Script
use IO::Socket;
my $remote_host = 'x.x.x.x';
my $remote_port = 'x';
my $socket = IO::Socket::INET->new(PeerAddr => $remote_host,PeerPort => $remote_port,Proto => 'tcp',Type => SOCK_STREAM) || die "Couldn't connect to $remote_host\:$remote_port : $!\n";
print $socket "This is a test line - hello world\n";
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-21-2007 12:11 AM
тАО06-21-2007 12:11 AM
Re: Perl Network Printing Script
What printer are you using specifically ?
515 for LPD based printers.
I want to print doc to printer MYPRINTER port 515.
Appreciate your help
JC.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-21-2007 12:50 AM
тАО06-21-2007 12:50 AM
Re: Perl Network Printing Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-21-2007 01:25 AM
тАО06-21-2007 01:25 AM
Re: Perl Network Printing Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-21-2007 01:47 AM
тАО06-21-2007 01:47 AM
Re: Perl Network Printing Script
>> Are you wanting suggestions or are you >>wanting some one to write the script for you?
I do not someone to write the script for me. That will defeat the whole purpose of me learning(well trying)to learn perl.
Suggestion, example, will be appreciated.
JC.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-21-2007 01:55 AM
тАО06-21-2007 01:55 AM
Re: Perl Network Printing Script
I did make some progress, well I can print doc to my network printer.
Following are my script.
I'm not sure how to print heading.
use strict;
use vars '@ARGV';
use Net::LPR;
use IO::File;
#if (scalar(@ARGV) < 2){die "\\nUsage: $0
my $var0 = "myfile.txt";
my $var1 = 'printer';
my $lp = new Net::LPR(
StrictRFCPorts => 0,
RemoteServer => $var1,
RemotePort => 515,
PrintErrors => 0,
RaiseErrors => 0,
) || die "Can't create print context\n";
my $fh = new IO::File $var0, O_RDONLY or die "Can't open $var0: $!\n";
#my $fh = new IO::File $ARGV[0], O_RDONLY or die "Can't $ARGV[0] $!\n";
my $size = ($fh->stat())[7];
$lp->connect() || die "Can't connect to printer $var1: ".$lp->error."\n";
my $jobkey = $lp->new_job() || die "Can't create new job: ".$lp->error."\n";
$lp->send_jobs('lp') || die "Can't send jobs: ".$lp->error."\n";
# Can easily print postscript by changing method to job_mode_postscript
$lp->job_mode_text($jobkey) || die "Can't set job mode to text: ".$lp->error."\n";
$lp->job_send_control_file($jobkey) || die "Can't send control file: ".$lp->error."\n";
$lp->job_send_data($jobkey, '', $size);
while (my $line = $fh->getline())
{
$lp->job_send_data($jobkey, $line);
}
$lp->disconnect();
__END__
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-21-2007 08:59 PM
тАО06-21-2007 08:59 PM
Solutionthe generic (OO interface) for Internet sockets in Perl would be IO::Socket::INET
(if you are more used to the procedural BSD Socket API you could also use the Perl Socket module, but this requires more function calls and awkward address translations).
However, this leaves the burden of compliance to the application's protocol to you.
So, fine that you found a more specialized module like Net::LPR.
I have to admit that I have never used it,
but I guess you found your way by its POD.
Maybe just a few "hints"?
There is no need to "use vars" on @ARGV
as this is implicitly a package global.
Besides, "use vars" is obsolete, and globals should be declared by "our" instead.
Also there is no need to scalar @ARGV if Perl can find out the ("Do What I Mean") context by itself.
So "if (@ARGV < 2)" should suffice.
But it never hurts to be explicit.
As you aren't using much functionality of IO::File (or those inherited from IO::Handle)
it seems a bit wasteful.
For instance to get the size of a file this would suffice: "my $size = -s $fh" (see perldoc -f -s).
So you don't even need to call stat().
Instead of instatiating an IO::File object
you could use a simple open() of the file whose content is to be printed.
If you passed that (or more) file(s) as arguments along with your Perl script invocation some further magic happens,
in that the file is implicitly opened and its name temporarily stored in $ARGV.
Then by assigning the buffer variable in the read loop to "<>" you can even omit the getline() call.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-21-2007 11:48 PM
тАО06-21-2007 11:48 PM
Re: Perl Network Printing Script
I appreciate your feedback/pointers.
Thread Close.
JC.