• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

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

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
cosmowen
Asked:
cosmowen
  • 4
  • 4
1 Solution
 
Alf666Commented:
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
 
cosmowenAuthor Commented:
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
 
Alf666Commented:
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
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
cosmowenAuthor Commented:
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
 
Alf666Commented:
Nah. that was a 'C' statement.
You could try :

fp_out << '\007' ;

0
 
cosmowenAuthor Commented:
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
 
Alf666Commented:
You might want to post a request in the support section (see link on top of page).

Thanks.
0
 
cosmowenAuthor Commented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now