Solved

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

Posted on 2004-04-21
8
172 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
  • 4
  • 4
8 Comments
 
LVL 9

Accepted Solution

by:
Alf666 earned 75 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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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
 

Author Comment

by:cosmowen
ID: 10893136
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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 fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now