[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

opening /dev/lp0 for output

Posted on 2004-10-29
5
Medium Priority
?
759 Views
Last Modified: 2013-12-15
I'm creating a QT application running on RH9.  I want to send a message to the printer when certain events happen. This is the code. strMsg is a QString.

  // now print the message to the printer
  int fid = open("/dev/lp0", O_WRONLY);
  if (fid < 0)
    {
    QMessageBox::warning(this, "We Got A Problem Boss",
                        "Can't write alarms to the printer!\n");
    }
  else
    {
    // must be open if we got this far.  write the alarm message
    strMsg.append("\n");
    int intCharsOut = write(fid,strMsg, strMsg.length());
    qDebug("Wrote %d chars",intCharsOut);
    close( fid );
    qDebug("Closed the file");
    }

This code works fine ... one time.  When the code tries to print the second message, it fails to open /dev/lp0.

What changes need to be made so I can print multiple messages?

don ;{)
0
Comment
Question by:holyfeld
[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
  • 3
  • 2
5 Comments
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 12449747
You may want to open the device file only once when your program starts, then write the messages to the printer, and close the file again when your program is done.
0
 

Author Comment

by:holyfeld
ID: 12463622
This works, sort of.  It does solve the "failure to open /dev/lp0" problem.  However, it also prevents lp0 from receiving print jobs from the print manager.  

ls -l lp0 returns
crw-rw-rw-    1 root     lp         6,   0 Jan 30  2003 lp0

do I need to set some other access/privilege?

don ;{)
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 12463949
Because you are always in conflict with a print spooler when you write directly to the printer device, it's a bad idea to do this in the first place. What if you write a line, then give up the device, the printer spooler sends a job, then you open the device and print another line? Do you want your logs intermixed with normal print jobs?

I don't know how the printer port is actually controlled (haven't done this for probably ten years), but I can lookup some information for you.
0
 

Author Comment

by:holyfeld
ID: 12464924
"Because you are always in conflict with a print spooler when you write directly to the printer device, it's a bad idea to do this in the first place."

I agree.  The user will be back tomorrow.  I'll share the "news" with him and see what he says.

Can you point me to th information on who the printer port is controlled. I'm replacing a DOS application that does the open/write/close sequence with no problem.  They're using ?DesqView? and occasionally go to another window to print reports.

don ;{)
0
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 1000 total points
ID: 12465268
There is a man page that describes the ioctl interface for the lp device (online version can be found e.g. here: http://jamesthornton.com/linux/man/lp.4.html).
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month14 days, 14 hours left to enroll

649 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