source for printing file or generated output...

Posted on 1999-01-11
Last Modified: 2010-04-21
I am working on a SCO box,  with C.   What I am doing is writing a labels program for a client and would like to know the best of going about sending info to the printer of choice.  I had asked a question like this earlier, but instead of a file, I would like to send output to the printer.  For example,  if my program got data like this:

John Smith
1234 General Drive
Some City, Some State, 12345

how would I go about sending that to printer??  I could open the dev file myself, but that could cause problems.  The way I had thought about doing was to generate a temp file then print the file, but I don't think that is a good way of doing it.  Thanks guys.
Question by:kellyjj
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 2008689
To print in POSIX OS u can redir a output stream to device directy, for example:
cat myfile > /dev/device_name
print "John Smith\n1234 General Drive\nSome City, Some State,\n12345\n\f" > /dev/device_name
if u need print in C
FILE *fp;
fprintf(fp,"%s\n%s\n%s\n%s\n%s\n\f","John Smith","1234 General Drive","Some City, Some State,","12345");

bye bye xcuse my english


Author Comment

ID: 2008690
thanks for your help, however, writing directly to the printer port would cause problems with the spooler.  Basically what I want is to send output to the spooler and let The OS handle it.

Expert Comment

ID: 2008691
u can try redirect or write to spooler like a device, the difference is in /dev/spool/nameofspool
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 2008692
If your program is "myprog" and your printer "myprt"
then enter :
myprog | lp -dmyprt

Accepted Solution

mliberi earned 200 total points
ID: 2008693
The best way to do the job is using the 'popen' function

FILE *w = popen("lp -dmyprt","w");

if (!w) { /* manage error condition */ }
fprintf(w,"%s\n%s\n%s\n%s\n%s\n\f","John Smith","1234 General Drive","Some City, Some State,","12345");

Author Comment

ID: 2008694
thanks,  that is what I figured out.  Nice to see that I was going down the right road.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (, discussed installing the Solaris Operating S…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question