Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.misc > #14359 > unrolled thread

How do you access the printer in Linux/C?

Started bypureheart@pacbell.net
First post2015-04-06 17:07 -0700
Last post2015-04-09 15:39 -0700
Articles 3 on this page of 23 — 10 participants

Back to article view | Back to comp.os.linux.misc


Contents

  How do you access the printer in Linux/C? pureheart@pacbell.net - 2015-04-06 17:07 -0700
    Re: How do you access the printer in Linux/C? Tim Watts <tw_usenet@dionic.net> - 2015-04-07 04:23 +0100
      Re: How do you access the printer in Linux/C? The Natural Philosopher <tnp@invalid.invalid> - 2015-04-07 05:46 +0100
      Re: How do you access the printer in Linux/C? floyd@apaflo.com (Floyd L. Davidson) - 2015-04-07 02:16 -0800
        Re: How do you access the printer in Linux/C? Tim Watts <tw_usenet@dionic.net> - 2015-04-07 11:30 +0100
          Re: How do you access the printer in Linux/C? The Natural Philosopher <tnp@invalid.invalid> - 2015-04-07 11:51 +0100
            Re: How do you access the printer in Linux/C? floyd@apaflo.com (Floyd L. Davidson) - 2015-04-07 03:11 -0800
              Re: How do you access the printer in Linux/C? The Natural Philosopher <tnp@invalid.invalid> - 2015-04-07 12:37 +0100
                Re: How do you access the printer in Linux/C? pureheart@pacbell.net - 2015-04-07 08:31 -0700
            Re: How do you access the printer in Linux/C? Tim Watts <tw_usenet@dionic.net> - 2015-04-07 12:24 +0100
          Re: How do you access the printer in Linux/C? Charlie Gibbs <cgibbs@kltpzyxm.invalid> - 2015-04-07 16:26 +0000
        Re: How do you access the printer in Linux/C? The Natural Philosopher <tnp@invalid.invalid> - 2015-04-07 11:46 +0100
        Re: How do you access the printer in Linux/C? Unknown <dog@gmail.com> - 2015-05-06 08:50 +0000
          Re: How do you access the printer in Linux/C? Joe Beanfish <joebeanfish@nospam.duh> - 2015-05-06 13:36 +0000
            Re: How do you access the printer in Linux/C? Unknown <dog@gmail.com> - 2015-05-08 10:44 +0000
              Re: How do you access the printer in Linux/C? Joe Beanfish <joebeanfish@nospam.duh> - 2015-05-08 13:51 +0000
                Re: How do you access the printer in Linux/C? William Unruh <unruh@invalid.ca> - 2015-05-08 14:58 +0000
                  Re: How do you access the printer in Linux/C? Joe Beanfish <joebeanfish@nospam.duh> - 2015-05-11 13:24 +0000
                    Re: How do you access the printer in Linux/C? Robert Heller <heller@deepsoft.com> - 2015-05-11 14:40 -0500
              Re: How do you access the printer in Linux/C? William Unruh <unruh@invalid.ca> - 2015-05-08 14:55 +0000
    Re: How do you access the printer in Linux/C? The Natural Philosopher <tnp@invalid.invalid> - 2015-04-07 05:43 +0100
    Re: How do you access the printer in Linux/C? Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-04-07 12:15 -0400
      Re: How do you access the printer in Linux/C? pureheart@pacbell.net - 2015-04-09 15:39 -0700

Page 2 of 2 — ← Prev page 1 [2]


#14365

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2015-04-07 05:43 +0100
Message-ID<mfvn99$v23$2@news.albasani.net>
In reply to#14359
On 07/04/15 01:07, pureheart@pacbell.net wrote:
> I ended up writing my input to a file and then calling 'mpage | lpr" with the system command.
>
> Works fine, but, tell me, how to I get to the printer w/o going throuph LP(R) in some way?

That's not a bad way but actually Cups is more sys5 so lp rather than 
lpr is the one to use.

I would suspect you could open a direct socket call to the cups daemon.

But really that's pretty much all lp does apart from parsing command 
line args and setting options in cups.


Might be worth getting the source of the lp program and hacking at that....


-- 
Everything you read in newspapers is absolutely true, except for the 
rare story of which you happen to have first-hand knowledge. – Erwin Knoll

[toc] | [prev] | [next] | [standalone]


#14382

FromLew Pitcher <lew.pitcher@digitalfreehold.ca>
Date2015-04-07 12:15 -0400
Message-ID<BoTUw.218313$ID6.16820@fx15.iad>
In reply to#14359
On Monday April 6 2015 20:07, in comp.os.linux.misc, "pureheart@pacbell.net"
<pureheart@pacbell.net> wrote:

> Might really be a programming question.
> 
> Back in my CBASIC days, the command LPRINTER would cause all PRINT
> statemets to be directed to the printer (LPT:) until you issued the
> command CONSOLE to return it to the screen (CON:).
> 
> When I wrote a simple envelope printing program when I changed over from
> CP/M to Linux (no MS in this house) I could not find how to do that with
> standard 'C'.
> 
> I ended up writing my input to a file and then calling 'mpage | lpr" with
> the system command.
> 
> Works fine, but, tell me, how to I get to the printer w/o going throuph
> LP(R) in some way?

In general, you don't.

If you have the requisite permissions, you could open() /dev/lp and write to
it. This will require you to know *exactly* how the *specific* printer
device attached to that /dev node expects it's data (most often, it is
*not* a straight copy of the text data you want to print), and how the
device wishes to communicate back to you.  *THIS IS NOT THE RECOMMENDED WAY
TO PRINT FROM A PROGRAM*

To print from a program, you

  #include <stdio.h>
  {
    FILE *printer;

    /* see lpr(1) for appropriate lpr options */
    printer = popen("lpr","w"); /* with appropriate error checking */

    fprintf(printer,"This is my text to the printer\n");

    pclose(printer);
  }

for example:

/*
** Sample program to illustrate how to spool a plain text
** report to the Linux print system.
*/

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
  FILE *spool;
  int line_no;

  if ((spool = popen("lpr -J \"Plain text print test\"","w")) == NULL)
  {
    fprintf(stderr,"Failed to connect to print spooler\n");
    return EXIT_FAILURE;
  }

  fprintf(spool,"Plain text spool test\n");
  for (line_no = 0; line_no < 20; ++line_no)
    fprintf(spool,"Line %d - test test test test test\n",line_no);

  if (pclose(spool) == -1)
    fprintf(stderr,"Failed to correctly release spooled print\n");
  else
    printf("Report spooled successfully\n");

  return EXIT_SUCCESS;
}

[snip]

-- 
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request

[toc] | [prev] | [next] | [standalone]


#14436

Frompureheart@pacbell.net
Date2015-04-09 15:39 -0700
Message-ID<7c65baca-fd03-4c02-90c1-5475bbff9524@googlegroups.com>
In reply to#14382
On Tuesday, April 7, 2015 at 9:15:39 AM UTC-7, Lew Pitcher wrote:
> On Monday April 6 2015 20:07, in comp.os.linux.misc, ""
> <> wrote:
> 
> > Might really be a programming question.
> > 
> > Back in my CBASIC days, the command LPRINTER would cause all PRINT
> > statemets to be directed to the printer (LPT:) until you issued the
> > command CONSOLE to return it to the screen (CON:).
> > 
> > When I wrote a simple envelope printing program when I changed over from
> > CP/M to Linux (no MS in this house) I could not find how to do that with
> > standard 'C'.
> > 
> > I ended up writing my input to a file and then calling 'mpage | lpr" with
> > the system command.
> > 
> > Works fine, but, tell me, how to I get to the printer w/o going throuph
> > LP(R) in some way?
> 
> In general, you don't.
> 
> If you have the requisite permissions, you could open() /dev/lp and write to
> it. This will require you to know *exactly* how the *specific* printer
> device attached to that /dev node expects it's data (most often, it is
> *not* a straight copy of the text data you want to print), and how the
> device wishes to communicate back to you.  *THIS IS NOT THE RECOMMENDED WAY
> TO PRINT FROM A PROGRAM*
> 
> To print from a program, you
> 
<snip example>

Thanks for this great example.  Makes perfect sense now that I
see it done.

Pureheart in Aptos

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.os.linux.misc


csiph-web