• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 327
  • Last Modified:

source for printing file or generated output...

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

kellyjjAuthor Commented:
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.
u can try redirect or write to spooler like a device, the difference is in /dev/spool/nameofspool
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

If your program is "myprog" and your printer "myprt"
then enter :
myprog | lp -dmyprt
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");
kellyjjAuthor Commented:
thanks,  that is what I figured out.  Nice to see that I was going down the right road.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now