[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: debian-user-digest Digest V98 #78



you wrote:
>Question for the C crowd: I have a program which I wish to print an ordered
>text file. In the Linux Programmers Guide, the printer chapter shows how to
>directly talk to the printer port. I'd like to be able to send the text to the
>appropriate printer filter (and spooler). How would one go about doing that?
ok hows about this...
remember this is Unix (well ok..linux in't really truelly technically unix)
try this...
use lpd :)
the command is already there for you to use...it will be in 1 of 2 places...
/usr/bin/lpr
or /usr/local/bin/lpr
or...let the l-user set an environment variable if its differnt
(unless your program is running suid ...then you have to be more security oriented)
how about this...if you are sure printing i sthe way to go...
make a named pipe (use a temp directory)
fork and have the parent open for writing and the child just get the name...
then have the child invoke lpr with the fifo as the file to print :)
(actually execvp (or whatever the name is) so that it replaces itself with lpd)
hav ethe child exit after lpr is done (actually it will since it becomes replaced by lpd)
have the parent go aheead and write to the fifo..and just close it when it finishes...
then lpd will just read it and boom done...
(then just clean up by getting rid of the fifo
another way...actually a better way
same thing...except open a non-named pipe..just a normal one...
then have the child change file descriptor 1 (ie stdin ) to the read end of the pipe...
then just execute lpr so it reads from stdin
then..parent side is the same..but with no cleanup needed
when both sides close..the pipe is gone
tho...thats just my idea on how to do it...
-Steve
--
President CLinton has recently proposed a bill to make research into the area
of human genetic cloneing illegal.
If you are a US citizen, please call your congressman and help STOP this bill.
Help Keep politics out of science.
(I know this signature is long but its important--it will be changed to
something shorter and funnier at a later date)





--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
debian-user-request@lists.debian.org . 
Trouble?  e-mail to templin@bucknell.edu .


Reply to: