Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

why does "ls > /dev/lp0" teturn "permission denied"?

984 views
Skip to first unread message

Chris Roy-Smith

unread,
Apr 4, 2012, 9:14:37 PM4/4/12
to
Hi
Wanting to redirect program output from a CLI command to the printer I
tried:

ls > /dev/lp0

As that seems the logical thing to do, hopeing that the system will take
care of translating text to whatever is needed to be sent to the printer
for the expected text to be printed.

All I get is :

bash: /dev/lp0: Permission denied

Why did this not work?
Is there a simple way to redirect?
what is the required target for the redirection?

Thanks for any constructive comments.
Regards, Chris Roy-Smith

Lew Pitcher

unread,
Apr 4, 2012, 9:27:46 PM4/4/12
to
On Wednesday 04 April 2012 21:14, in alt.os.linux,
chris_r...@internode.on.net wrote:

> Hi
> Wanting to redirect program output from a CLI command to the printer I
> tried:
>
> ls > /dev/lp0
>
> As that seems the logical thing to do, hopeing that the system will take
> care of translating text to whatever is needed to be sent to the printer
> for the expected text to be printed.

It's not as simple as that. For simple ASCII text printers (like old
dot-matrix or teletype-like printers), that's the easiest way to get
printed output, but for more modern printers (inkjet, laser, anything that
takes a formatting language), you /might/ get proper output, but more than
likely, you'll just get hash trying to print that way.

However,
ls | lpr
will work on any system that has system control over it's printers. That's
pretty much all properly installed Linux distributions, these days.

>
> All I get is :
>
> bash: /dev/lp0: Permission denied
>
> Why did this not work?

"Permission denied" implies a permissions problem.
Does your userid or groupid have write access to /dev/lp0?

That is to say,
- are you running as root?
- Or, is your userid the owner of /dev/lp0, and is /dev/lp0 writable by
owner?
- Or do you belong to the group who's groupid is the group owner
of /dev/lp0, and is /dev/lp0 writable by group?
- Or, is /dev/lp0 writable by other?

If none of these conditions are true, then you aren't allowed to write to
the device. Sorry.

> Is there a simple way to redirect?

You've tried the simple way.

> what is the required target for the redirection?

Same answer.

> Thanks for any constructive comments.
> Regards, Chris Roy-Smith

--
Lew Pitcher

Chris Roy-Smith

unread,
Apr 4, 2012, 9:57:05 PM4/4/12
to
Thanks, piping to lpr gave the desired output from the printer.
The redirection I tried would not accept anything even as root.

J G Miller

unread,
Apr 5, 2012, 6:35:45 AM4/5/12
to
On Wednesday, April 4th, 2012, at 21:27:46h -0400, Lew Pitcher declared:

> However,
> ls | lpr
> will work on any system that has system control over it's printers.

Not on any system unless BSD style printing or BSD style client is installed.

Usually CUPS is now installed by default on most major GNU/Linux distributions

<http://www.cups.ORG/>

and the print command is the SysV form lp, with lp -d queue_name for a specific
queue and lpstat for print job details.

The lpr command is only available on a CUPS system if "cups-bsd" is installed
as well.


Lew Pitcher

unread,
Apr 5, 2012, 8:38:36 AM4/5/12
to
On Apr 5, 6:35 am, J G Miller <mil...@yoyo.ORG> wrote:
> On Wednesday, April 4th, 2012, at 21:27:46h -0400, Lew Pitcher declared:
>
> > However,
> >   ls | lpr
> > will work on any system that has system control over it's printers.
>
> Not on any system unless BSD style printing or BSD style client is installed.
>
> Usually CUPS is now installed by default on most major GNU/Linux distributions
[snip]
> The lpr command is only available on a CUPS system if "cups-bsd" is installed
> as well.

You should note that CUPS, as delivered by cups.org, includes the lpr
utility. Some Linux distributions break up the CUPS install into
pieces, sometimes separating out the "bsd" portions into their own
packages. This is not the case for every distro, and CUPS (by
default) /does/ include the commandline print tools (lpr, lpq, lpstat,
etc)

unruh

unread,
Apr 5, 2012, 10:21:59 PM4/5/12
to
On 2012-04-05, Chris Roy-Smith <chris_r...@internode.on.net> wrote:
> Hi
> Wanting to redirect program output from a CLI command to the printer I
> tried:
>
> ls > /dev/lp0
>
> As that seems the logical thing to do, hopeing that the system will take
> care of translating text to whatever is needed to be sent to the printer
> for the expected text to be printed.

Why would you assume that if you send stuff to the raw printer port,
that the system would translate it? You tell it to sent it directly, so
it sends it directly to the port.
If you want to print ls do
ls |lpr

that sends the output of ls to the printer program whose purpose is
precisely to translate and send it to the printer in the right format.
0 new messages