Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Telling a printer to print from with in my program??

Posted on 2004-04-21
8
Medium Priority
?
184 Views
Last Modified: 2010-04-22
Hello all

I am writing a C++ program on Kylix 3 IDE.  I need to build a string and send it to my printer for every transaction that occurs.  I have no problem building the string and I can save it to a  file.  If you guys could tell me how I tell LINUX to print my file (within my program mind you) and I need just normal "$lp -receipt reports.txt" command such as this.  This will print my saved reports file but i have to be outside my program in a terminal window.  Thanks for your help and here is a slimed down version of my code.

ofstream fp_out("reports.txt", ios::out);
string mHeader;
mHeader.assign("My Console program");
mHeader.append("some more stuff");
fp_out << mHeader << endl;
fp_out.close();

//here iswhere i need the command to send this reports.txt file to the printer
Thanks in advance for your help

-Nightbird
0
Comment
Question by:cosmowen
[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
  • 4
  • 4
8 Comments
 
LVL 9

Accepted Solution

by:
Alf666 earned 300 total points
ID: 10884325
The simplest here would be to use the "system" C library call.
It does in fact a fork(), and an exec of a shell command.

So you can system("lp myfile.txt").

It's not the best programming method, but works pretty well.
0
 

Author Comment

by:cosmowen
ID: 10888925
THanks that is what i was looking for something short and sweet now for bonus points::: is there any way that you know to put an ascii '007' bell character to said file so that my printer will open its drawer.  The printer is a basic star receipt printer and a drawer plugs into the back of it and I need the drawer to open when the printer prints, I also need to send the printer a command that tells it to use its autocutter.  (if you have any clue about this i would be greatly appreciative.  

THanks again for your help
-Nightbird
0
 
LVL 9

Expert Comment

by:Alf666
ID: 10889024
I don't know in C++, but in C, you can do a :
fputc(7, myStream) ;

I don't know about the autocutter. But if you have any control character, just do the same as above.

0
AWS Certified Solutions Architect - Associate

This course has been developed to provide you with the requisite knowledge to not only pass the AWS CSA certification exam but also gain the hands-on experience required to become a qualified AWS Solutions architect working in a real-world environment.

 

Author Comment

by:cosmowen
ID: 10889992
ok i tried that but my stringstream won't accept it and the access to the file i am using is an ofstream so the fputc(7,fp_out) just gives me and error saying that it expects a _IO_FILE * and I don't know how to convert an fstream to a _IO_FILE * do you know an easy way to convert this??  if not then do you know how to give a stringstream a ascii value, I keep getting a 'argument not recognized' error no method for string.append(int) i wil keep poking around and thanks for your help.

-Nightbird
0
 
LVL 9

Expert Comment

by:Alf666
ID: 10890873
Nah. that was a 'C' statement.
You could try :

fp_out << '\007' ;

0
 

Author Comment

by:cosmowen
ID: 10891018
i managed to get it into my string by doing myString.append(1,char(7)); and it worked great now i am just trying to figure out what character to send the printer so that it cuts but I already know you don't know how so thanks for your help it is greatly appreciated.  Now the only question i have for you is how do i give you bonus points, i have done multipoints distrbitutions before but never to give bonus but there must be a way.  


!!MODS LOOK HERE :: how do I add bonus points or if I can't can you give Alf666 an extra 50 points for me.

Thanks
-Nightbird
0
 
LVL 9

Expert Comment

by:Alf666
ID: 10891384
You might want to post a request in the support section (see link on top of page).

Thanks.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

722 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