Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8055623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:26:46+00:00 2026-06-05T08:26:46+00:00

So, first things first, we cannot use the javax print services because it is

  • 0

So, first things first, we cannot use the javax print services because it is extremely slow as we have more than 20,000 printers installed on a machine (the lookup uses lpstat which is incredibly slow). So, we’re using lpr.

When I do this:

cat myfile.pdf | lpr -P "MyPrinter"

it prints the file perfectly to the printer name MyPrinter. To do the same in Java, I’m doing this:

cmd = String.format("lpr -P \"%s\"", "MyPrinter");

Process p = Runtime.getRuntime().exec(cmd);

OutputStream out = p.getOutputStream();

/*
 This essentially runs a thread which reads from a stream and
 outputs it to the STDOUT. This is what I've written to help with
 debugging
*/
StreamRedirect inRed = new StreamRedirect(p.getInputStream(), "IN");
StreamRedirect erRed = new StreamRedirect(p.getErrorStream(), "ER");

inRed.start();
erRed.start();


/*
 This is where I write to lprs STDIN. `document` is an InputStream
*/

final byte buf[] = new byte[1024];
int len;

while((len = document.read(buf)) > 0) {
    out.write(buf, 0, len);
}

out.flush();
out.close();

But, I get the following error:

SR[ER]>>lpr: The printer or class was not found.

Here, SR[ER] is just a custom label that is prefixed by the StreamRedirect. Why is this happening? Why is it able to find a printer when I run it from my command line, but not otherwise?

Also, I tried to run whoami from within the Java program and it says that I am running it as the same user I am logged in as (the same user with which I execute lpr on the command line).

Any help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T08:26:47+00:00Added an answer on June 5, 2026 at 8:26 am

    You need to put the command and the arguments in a string array

    String[] cmd = new String[] { "lpr" , "-P", "MyPrinter" };
    
    Process p = Runtime.getRuntime().exec(cmd);
    

    You might also want to use the newer ProcessBuilder class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all i have to clear few things 1.This is not spam group
So first things first the only reason I include IE in this is its
One of the first things I learned in C++ was that #include <iostream> int
One of the first things I like to do when I make a site
One if the first things I learned when I started with C# was the
I know the bits just came out today, but one of the first things
I was just wondering how C++ compilers deal with certain things: First, how do
I am reading some json output... just some integers. The first NSLog outputs things
Two things, first this is my first question in this forum and I do
There are two things I do not understand too well in this scenario First,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.