# # (SCO Unix) How can I make a device that will print to a network printer?
APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

SCO Unix/System V Printing FAQ

I've removed advertising from most of this site and will eventually clean up the few pages where it remains.

While not terribly expensive to maintain, this does cost me something. If I don't get enough donations to cover that expense, I will be shutting the site down in early 2020.

If you found something useful today, please consider a small donation.



Some material is very old and may be incorrect today

© December 2003 Anthony Lawrence

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 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.

How can I make a SCO Unix/System V 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:

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 :
do
exec </dev/myfakenetprint 
lp -dmyrealnetprinter
done
 

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

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

Or:

while :
do
exec </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 writing process 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.

You can use this same concept to implement "printers" that send email, queue faxes or do anything else you need done.

See Race conditions also.

If you found something useful today, please consider a small donation.



Got something to add? Send me email.





(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

->
-> (SCO Unix) How can I make a device that will print to a network printer?


Inexpensive and informative Apple related e-books:

Take Control of Upgrading to El Capitan

Take Control of Parallels Desktop 12

Photos for Mac: A Take Control Crash Course

Take Control of OS X Server

Take Control of Pages





More Articles by © Anthony Lawrence





Printer Friendly Version

Have you tried Searching this site?

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.

Contact us


Printer Friendly Version





Any teacher that can be replaced with a computer, deserves to be (David Thornburg)




Linux posts

Troubleshooting posts


This post tagged:

FAQ

Mail

Printing



Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode