This article is from a FAQ concerning SCO operating systems. While some of the information may be applicable to any OS, or any Unix or Linux OS, it may be specific to SCO Xenix, Open Desktop or Openserver.

There is lots of Linux, Mac OS X and general Unix info elsewhere on this site: Search this site is the best way to find anything.

Printing FAQ

How can I make a device that will print to a network printer?

First, are you really sure you need to do this? Only very lame software can't handle a spooled printer. However, if you must:


Hate these ads?

The basic concept is to create a named pipe. For example, you might do this:

mknod /dev/myfakenetprint p

That creates a "device" that your application can print to. Use "chmod" as necessary to give it whatever permissions you need (666 if everyone needs to use it).

Now you need something that runs all the time in background. It's a shell script (see New to Unix if you don't know how to make a shell script) and it needs to start automatically whenever the machine is rebooted (see Automating Program Startup). This script assumes that your network printer already exists in the spooler:

while true
do
cat /dev/myfakenetprint | lp -dmyrealnetprinter
done

Some folks have found that this works better in some places:

while true
do
exec </dev/myfakenetprint 
lp -dmyrealnetprinter
done

You could also use hpnpf or netcat (see Network Printing ) directly:

while true
do
cat /dev/myfakenetprint | netcat -h printername -p 3001
done

These work because the "cat" will hang until something (your application) writes data to the named pipe. The "lp" won't complete until cat is done reading, which will be when your application closes its writing. Although it might look like this ties up your cpu, it doesn't- the cat sleeps while it hangs, and so does lp or netcat: there's nothing going on until you write data to the named pipe. If switching from a serial environment, you may find How can I assign a user process to a specific pseudo tty? useful also.






On a very busy system, it's possible for the lp system to send new data to the pipe before your reader process has sent it to the print server. You could implement a cooperative locking system to prevent that, but a small sleep at the end of the interface script will probably work.

See Race conditions also.



Comments /SCOFAQ/FAQ_scotec7netdevice.html


Add your comments

ad

Enter your email address for automatic notification of new posts here
(be sure to whitelist 'feedburner.com' if you use spam filtering)

Or use any RSS reader

Delivered by FeedBurner

cartoon
Forget the expense of flying to New England. Forget hotel and meals costs.
Installation and light training Boston and New England


Views for this page
Today This Week This Month This Year  Overall
37651,386 1,638

/SCOFAQ/FAQ_netdevice.html copyright 1997-2003 (various) All Rights Reserved

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

More:
       - FAQ




Unix/Linux Consultants

Your ad here - $24.00 yearly!

http://bcstechnology.net Full service Linux & UNIX systems integrator; Windows to UNIX/Linux Client-Server Specialist; Secure E-Mail & Website Hosting; Thoroughbred Software Developer; Custom Industrial Automation; Hardware & Electronics Experts; In Business Since 1985.


UBB Computer Services Support for Openserver, Unixware and Linux. Windows integration with Unix/Linux servers. Hardware, Backup and Networking issues. Located near Sacramento CA, we provide onsite support throughout Northern CA and Nationwide via remote access. We are a SCO Authorized Partner and a Microlite BackupEdge Certified Reseller.


http://thatitguy.com Business networking servers, Linux and Unix experts. In business since 1997! Windows and Exchange to Samba and Scalix migration experts.









Change Congress


Related Posts