Solved

source for printing file or generated output...

Posted on 1999-01-11
6
298 Views
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.
0
Comment
Question by:kellyjj
6 Comments
 

Expert Comment

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


bye bye xcuse my english







0
 
LVL 2

Author Comment

by:kellyjj
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.
0
 

Expert Comment

by:tato
ID: 2008691
u can try redirect or write to spooler like a device, the difference is in /dev/spool/nameofspool
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 1

Expert Comment

by:toTo
ID: 2008692
If your program is "myprog" and your printer "myprt"
then enter :
myprog | lp -dmyprt
0
 
LVL 3

Accepted Solution

by:
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");
pclose(w);
0
 
LVL 2

Author Comment

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

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

Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

792 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