-
Printing with printer
Hi, I've made a program to print in Linux. The steps are:
1. Open a new temporary LaTeX file
2. Insert the strings to be printed in LaTeX
3. Close and save the temporary LaTeX file
4. Convert the temporary LaTeX file to DVI file in the shell
5. Convert the DVI file to PS file in the shell
6. Print the PS file with CUPS
7. Delete all the temporary files
The code is like this:
Code:
//Print to file
fstream filestr;
//Insert LaTeX code and strings to be printed here
..........
filestr.close();
//Print this!!!!!
int jobid;
int num_dests;
cups_dest_t *dests;
// Get printer destinations
num_dests = cupsGetDests(&dests);
cups_dest_t *mydest;
// Get the default printer
mydest = cupsGetDest(NULL, NULL, num_dests, dests);
//Convert to DVI
system("latex ./temp-print.tex");
//Convert to PS
system("dvips temp-print -t landscape -o temp-print.ps");
//Print to default printer
jobid = cupsPrintFile(mydest->name, "./temp-print.ps", "tes", 0, NULL);
if (jobid == 0)
puts(ippErrorString(cupsLastError()));
else
{
SDL_Delay(20000); //Delay to make sure the printing job finished
int status;
status = cupsCancelJob(mydest->name, jobid);
system("rm -f ./temp-print.*"); //Delete all temporary files
}
The code works fine. But the problem is, when I executed the code, my program is kind of lagging. I suspected it's because I used 3 calls to sh ( system("latex ./temp-print.tex"); , system("dvips temp-print -t landscape -o temp-print.ps"); , system("rm -f ./temp-print.*"); ). How can I make my program run smoothly?
Thanks in advance.
PS: I see that the board has been maintenanced recently because I couldn't find my previous messages prior to August 2006.
-
> my program is kind of lagging
SDL_Delay(20000);
Got it yet?
> PS: I see that the board has been maintenanced recently because I couldn't find my previous messages prior to August 2006
I can see all posts for user quite happily.
The main forum list is usually limited by "Display Options" (bottom left)
Pick a bigger date range, or find all posts you posted from looking at your own profile.
-
The delay didn't have anything to do with the lagging. FYI, I'm using SDL to make some animation and the printing code is in a diferent thread with the animation thread. The delay is only used to make sure the printing job has been done and canceled the job, because for some reason the job gets stuck even if it was already done with its printing. The one that's lagged was the animation thread. It gets kind of halted for a few milisecond when the printing thread called sh.
Thanks.
-
Well, system() is known to be slow. There's not much you can do about it, except maybe try exec*() or the equivalent Win32 function.
-
I doubt he can use Win32 functions under linux.
-
You're probably right. :) But [s]he can most likely use exec* or (most likely, if you want to function to return) spawn*.