Solved

source for printing file or generated output...

Posted on 1999-01-11
6
316 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
[X]
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
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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

630 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